-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.js
More file actions
31 lines (26 loc) · 851 Bytes
/
routes.js
File metadata and controls
31 lines (26 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require('express');
const { exec } = require('child_process');
const path = require('path')
const cors=require('cors');
const app = express();
app.use(express.json())
app.use(express.static("public"));
app.use(cors())
app.get('/resource', (req, res) => {
exec('bash resource.sh', (err, stdout, stderr) => {
if (err) {
console.error('Error executing script:', err);
res.status(500).json({ error: 'An error occurred' });
} else if (stderr) {
console.error('Script encountered an error:', stderr);
res.status(500).json({ error: 'Script error' });
} else {
let data=JSON.parse(stdout)
res.json(data);
}
});
});
app.get("/",(req,res)=>{
res.sendFile(path.join(__dirname,"public","index.html"))
})
module.exports = app;