-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
50 lines (36 loc) · 1.31 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
import bodyParser from 'body-parser';
import cors from 'cors';
import express from 'express';
import expressValidator from 'express-validator';
import logger from 'morgan-body';
import path from 'path';
import auth from './middlewares/auth'
import config from './config';
import clients from './routes/clients';
import dockerflow from './routes/dockerflow';
import users from './routes/users';
import sensorthings from './routes/sensorthings';
let app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator({
customValidators: {
isArrayOfUrls: (value, options) => {
const validator = expressValidator.validator;
return Array.isArray(value) &&
value.every(item => validator.isURL(item, options));
}
}
}));
app.use(bodyParser.json());
if (config.get('env') !== 'test') {
logger(app);
}
app.use(cors());
app.use('/', dockerflow);
app.use('/', sensorthings);
const endpointPrefix = '/' + config.get('version');
app.use(endpointPrefix + '/clients', auth(['admin']), clients);
app.use(endpointPrefix + '/users', users);
const port = config.get('port');
app.listen(port, () => console.log(`Running on localhost:${port}`));
exports = module.exports = app;