-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
48 lines (41 loc) · 1.4 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
/**
* @file
* Define the server bind
*
* This code is the property of Epitech
* Contact: [email protected]
*/
'use strict';
require('node-fetch');
require('dotenv').config();
var express = require('express'),
app = express(),
port = 8080,
bodyParser = require('body-parser'),
helmet = require('helmet'),
jwt_decode = require('jwt-decode');
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(function(req, res, next) {
let now = new Date();
let date = now.getDate() + '-' + (now.getMonth() + 1) + '-' + now.getFullYear() + '/' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
if (req.headers !== undefined && req.headers.authorization !== undefined) {
try {
console.log(date, jwt_decode.jwtDecode(req.headers.authorization.split(' ')[1]).login, req.socket.remoteAddress, req.method, req.originalUrl);
next();
} catch (e) {
console.log(date, 'undefined', req.socket.remoteAddress, req.method, req.originalUrl);
res.sendStatus(400);
}
} else {
console.log(date, req.socket.remoteAddress, req.method, req.originalUrl);
next();
}
});
console.log('============== STARTING SERVER ==============');
var http = require('http');
http.createServer(app).listen(port);
require('./api/routes/cardRoutes')(app);
require('./api/routes/presenceRoutes')(app);
module.exports = app;