This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (45 loc) · 1.55 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
const express = require('express');
const router = express.Router();
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const _ = require('lodash');
const indexRouter = require('./routes/index');
const nocache = require('nocache');
const Constants = require('./lib/constants');
const app = express();
app.disable('x-powered-by');
app.set('etag', false);
app.use(logger('dev'));
const bodyParser = require('body-parser');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.use(bodyParser.json({ type: 'application/*+json' }));
// Never cache
app.use(nocache());
app.use(function (req, res, next) {
const headers = _.clone(req.headers);
headers['x-forwarded-for'] = Constants.getClientIp(req);
headers.accept = 'application/json';
delete headers['link'];
if (req.header('NGSILD-Tenant')) {
res.locals.tenant = req.header('NGSILD-Tenant');
headers['fiware-service'] = res.locals.tenant;
delete headers['ngsild-tenant'];
}
if (req.query.scopeQ) {
const scope = req.query.scopeQ;
const servicePath = scope.startsWith('/') ? scope : '/' + scope;
res.locals.servicePath = servicePath;
headers['fiware-servicepath'] = servicePath;
} else {
headers['fiware-servicepath'] = '/';
}
res.locals.headers = headers;
next();
});
app.use('/ngsi-ld/v1', indexRouter);
app.use('//ngsi-ld/v1', indexRouter);
module.exports = app;