-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (43 loc) · 1.43 KB
/
app.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
52
53
54
55
56
57
58
59
60
const express = require('express');
const path = require('path');
const { exec } = require('child_process');
const fs = require('fs');
const app = express();
const PORT = 4000;
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.render('index');
});
app.get('/generateTopology', (req, res) => {
exec('sudo python3 scripts/generateTopology.py');
});
app.get('/topology/:type', (req, res) => {
const topologyType = req.params.type;
const allowedTopologies = ['bus', 'star', 'ring', 'mesh', 'tree', 'fully_connected'];
if (!allowedTopologies.includes(topologyType)) {
return res.status(400).send('Invalid topology type');
}
const outputFile = path.join(__dirname, 'topology', `${topologyType}_topology.json`);
if (fs.existsSync(outputFile)) {
res.sendFile(outputFile);
} else {
res.status(500).send('Topology file not generated');
}
});
app.get("/simulator",(req,res)=>{
res.render("simulator");
})
app.get("/pathfinder",(req,res)=>{
res.render("pathFinder");
})
app.get("/icmp",(req,res)=>{
res.render("icmp_star");
})
app.get("/tcp",(req,res)=>{
res.render("protocolSimulation/tcp");
})
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});