-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (62 loc) · 2.12 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');
const bodyParser = require('body-parser');
const routes = require('./api/routes');
const security = require('./config/security');
const passport = require('passport');
const fs = require('fs');
const morgan = require('morgan');
const path = require('path');
const logger = require('./config/winstonLogger');
const busboy = require('connect-busboy'); //https://github.com/mscdex/connect-busboy
const compression = require('compression');
const xss = require('xss-clean');
const cookieParser = require('cookie-parser');
const redisClient = require('./utils/redis');
const database = require("./service/database");
const app = express();
app.use(helmet());
const router = express.Router();
const port = 3000;
const host = '127.0.0.1';
const LOG_FILE_NAME = 'access.log';
const LOG_DIRECTORY = __dirname;
const accessLogStream = fs.createWriteStream(
path.join(LOG_DIRECTORY + '/logs', LOG_FILE_NAME), { flags: 'a' });
app.use(morgan('combined', { stream: accessLogStream }));
app.use(cors());
// Setting up the public directory
app.use(express.static('public', {
setHeaders: (res) => {
res.set('Cross-Origin-Resource-Policy', 'crossorigin');
}
}));
app.use(compression());
app.use(cookieParser());
security.shibbolethAuthentication(app, passport);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: '1024kb' }));
app.use(xss());
database.query('SELECT NOW()', (err, res) => {
console.log(err ? "errors: " + err : 'Postgres client connected ' , res.rows[0]);
});
redisClient.on('connect', function() {
console.log('Redis client connected');
});
redisClient.on('error', function (err) {
console.log('Something went wrong ' + err);
});
// busboy middle-ware
router.use(busboy({
highWaterMark: 2 * 1024 * 1024, // Set 2MiB buffer
}));
app.use('/api', router);
routes(router);
const server = app.listen(port, host, () => {
logger.info(`lataamo proxy is listening on port ${port}!`);
});
server.requestTimeout = 18000000;
server.headersTimeout = 0
// for the tests
module.exports = app;