-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (50 loc) · 1.65 KB
/
server.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
61
62
63
64
const express = require('express');
const path = require('path');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackConfig = require('./webpack.config.js');
const fs = require('fs');
const app = express();
const port = 3000;
const compiler = webpack(webpackConfig);
app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
})
);
// Route to handle the GET request and serve the page
app.use('/home', express.static(path.join(__dirname, '..', 'REST', 'static')));
// Route to handle the GET request and serve the page
app.get('/openebench', (req, res) => {
res.sendFile(path.join(__dirname,'dist', 'index.html'));
});
// Route to handle the GET request and serve the page
app.get('/listAgents', (req, res) => {
fs.readFile(path.join(__dirname, 'data', 'AgentTopicAutocomplete.json'), 'utf8', (err, data) => {
if (err) {
return res.status(500).json({ error: 'Failed to read names file' });
}
let names = JSON.parse(data);
const hasTags = 'false';
names = names.filter( name =>{
const hasList = Array.isArray(name.labelnode);
return hasTags ? hasList : !hasList;
});
if (req.query.skip) {
const skip = parseInt(req.query.skip, 10);
if (!isNaN(skip) && skip > 0) {
names = names.slice(skip);
}
}
if (req.query.limit) {
const limit = parseInt(req.query.limit, 10);
if (!isNaN(limit) && limit > 0) {
names = names.slice(0, limit);
}
}
res.json(names);
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});