-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcapstone.js
51 lines (45 loc) · 1.42 KB
/
capstone.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require('express');
const cors = require('cors');
const { exec } = require('child_process');
const app = express();
const fs = require('fs');
const path = require('path');
app.use(cors());
app.use('/models', express.static('models'));
app.use(express.json());
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'webb.html'));
});
app.get('/load_obj.html', (req, res) => {
res.sendFile(path.join(__dirname, 'load_obj.html'));
});
app.get('/web.js', (req, res) => {
res.sendFile(path.join(__dirname, 'web.js'));
});
app.get('/files', (req, res) => {
const folderPath = 'C:/Users/ESE/Desktop/capstone/models';
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error(err);
return res.status(500).send('Internal Server Error');
}
res.json(files);
});
});
app.post('/execute-script', (req, res) => {
const fileName = req.body.fileName;
const scriptPath = `C:/Users/ESE/Desktop/capstone/models`;
const command = `cd "${scriptPath}" && instant-ngp ${fileName}`;
console.log(`Script output: ${fileName}`);
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing script: ${error.message}`);
return res.status(500).send('Error executing script');
}
console.log(`Script output: ${stdout} and ${fileName}`);
});
});
const PORT = 3050;
app.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});