-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (34 loc) · 1.25 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
const express = require('express');
const bodyParser = require('body-parser');
const nunjucks = require('nunjucks');
const argv = require('yargs')(process.argv.slice(2)).argv;
// use --localMode to run on a nexusedge gateway directly rather than on an auxiliary device
// const localMode = !!argv.local; // if undefined => false, otherwise true
const localMode = true;
console.log(`Local mode: ${localMode}`);
const app = express();
const port = (process.env.PORT || 4000);
//nunjucks
const PATH_TO_TEMPLATES = __dirname + '/api/views';
nunjucks.configure(PATH_TO_TEMPLATES, {
autoescape: true,
express: app
});
nunjucks.installJinjaCompat(); //for accessing additional filters like .values() on dictionary in nunjucks
//body parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
//static folder
app.use(express.static(__dirname + '/public'));
//Describe API endpoints in api/routes.js
const routes = require(__dirname + '/api/routes');
routes(app, {
localMode: localMode
});
app.listen(port, function() {
console.log(`Auxiliary Device Webapp started on port ${port}`)
});
//throw an error if it is an unknown endpoint
app.use(function(req, res) {
res.status(404).send(`${req.originalUrl} is not a valid endpoint.`);
});