-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
112 lines (91 loc) · 2.91 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*=====================Initialisation=====================*/
const express = require("express");
require('dotenv').config();
const app = express();
const http = require('http').Server(app);
const httpd = require('https');
const fs = require('fs');
const bodyParser = require('body-parser')
const ejs = require('ejs');
const path = require('path');
const session = require('express-session');
const esso = require('eve-sso-simple');
const url = 'mongodb://'+ process.env.DB_HOST +':'+ process.env.DB_PORT +'/' + process.env.DB_NAME;
const minify = require('express-minify');
var RedisStore = require('connect-redis')(session);
/*======================================================*/
const mongoose = require('mongoose');
mongoose.connect(url, { useNewUrlParser: true });
let db = mongoose.connection;
db.on('error', function(err){
process.exit(1)
});
db.once('open', function() {
console.log('Connected')
});
//define model
require('./models/model.js')(mongoose);
//logger
LOGS = require('./src/history.js');
// Middleware session
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'public/views'));
app.use(minify({cache: __dirname + '/cache'}));
if (!process.env.DEV) {
app.use(session({
resave: false,
saveUninitialized: false,
secret: process.env.COOKIE,
store: new RedisStore
}));
} else {
app.use(session(
{
secret: process.env.COOKIE,
saveUninitialized: false,
resave: false
}
));
}
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.enable('trust proxy');
// middlewere de secu
app.use(function (req, res, next) {
var _ = require('underscore')
, nonSecurePaths = ['/callback/', '/logout', '/test'];
if ( _.contains(nonSecurePaths, req.path) )
return next();
else if (!req.session.userinfo) {
esso.login(
{
client_id: process.env.C_ID,
client_secret: process.env.C_SECRET,
redirect_uri: process.env.CALLBACK
}, res);
} else if (req.session.db.role == 0){
res.render('under')
return null
} else if (req.session.db.role <= 0){
res.redirect('https://www.google.fr/search?biw=1920&tbm=isch&source=hp&biw=&bih=969&q=trash&oq=trash');
return null
} else {
return next()
}
});
/*======================routes==========================*/
/*------include fichier------*/
require('./src/remove.js')(app, path, ejs, fs);
require('./src/character.js')(app, path, ejs, fs);
require('./src/log.js')(app, path, ejs, fs, esso);
require('./src/members.js')(app, path, ejs, fs);
/*======================route fichier static (public)====================*/
app.use("/css", express.static(__dirname + '/public/css'));
app.use("/img", express.static(__dirname + '/public/img'));
app.use("/js", express.static(__dirname + '/public/js'));
/*==================start serv==================*/
http.listen(process.env.PORT, function(){
console.log('listening on *:' + process.env.PORT);
});