-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (56 loc) · 1.79 KB
/
index.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
const express = require('express');
const mongoose = require('mongoose');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const bluebird = require('bluebird');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const session = require('express-session');
const connectMongo = require('connect-mongo');
const compression = require('compression');
var MongoStore = connectMongo(session);
const config = require('./config');
const routes = require('./routes');
const filereader = require('./workers/file-reader');
const seed = require('./seed');
const app = express();
mongoose.Promise = bluebird;
mongoose.connect(config.mongo.url);
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(passport.initialize());
app.use(morgan('tiny'));
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, authorization");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
next();
});
//enable gz files
app.use(compression());
app.use('/api', routes);
app.use(express.static('client'));
// All other routes should redirect to the index.html
app.route('/*')
.get((req, res) => {
res.sendFile(__dirname + '/client/index.html');
});
app.use(session({
secret: config.secrets.session,
saveUninitialized: true,
resave: false,
store: new MongoStore({
mongooseConnection: mongoose.connection,
db: 'ipgard'
})
}));
app.listen(config.server.port, () => {
console.log(`Magic happens on port ${config.server.port}`);
});
seed.populateAdmin();
seed.populateTypes();
filereader(3, 0);
module.exports = app;