-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (46 loc) · 1.24 KB
/
app.js
File metadata and controls
56 lines (46 loc) · 1.24 KB
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
const graph = require('./graph-base.js');
const express = require('express');
const path = require('path');
const prepResponse = require('./fetch_algo');
const app = express();
const publicDirectoryPath = path.join(__dirname, '/graph-visualization');
var port = process.env.PORT || 8080;
app.use(express.static(publicDirectoryPath));
app.use('/public', express.static('public'));
app.use(express.json());
const prepErrorMsg = (error) => {
const err = {
result: 'Content Not found!',
error,
};
return JSON.stringify(err);
};
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
app.get('', (req, res) => {
res.sendfile('src/main.html');
});
app.get('/visual', (req, res) => {
res.sendfile('src/visual.html');
});
app.post('/api', (req, res) => {
try {
let respp = prepResponse(req.body['values'], req.body['algo']);
console.log(respp);
res.json(respp);
} catch (e) {
let errorMsg = prepErrorMsg(e);
res.status(404).json(errorMsg);
}
});
app.post('/dfs', (req, res) => {
let respp = prepResponse(req.body['values']);
console.log(respp);
res.json(respp);
});
app.listen(port, () => {
console.log(`Server is up on port ${port}.`);
console.log(publicDirectoryPath);
});