-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (54 loc) · 1.63 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var express = require('express'),
morgan = require('morgan'),
passport = require('passport'),
mongoose = require('mongoose/'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
models = require('./app/models'),
User = models.User,
MongoStore = require('connect-mongo')(session),
app = express(),
config=require("./config");
app.set('view engine', 'jade');
app.use(express.static(__dirname + '/static'));
app.use(morgan("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
secret: 'tuj7hzj6rfgt57ujhziofwefiweafweuihf34zr823jfvsbzvh8vb34hb4fsdfu83',
resave: true,
saveUninitialized: true,
store: new MongoStore({mongooseConnection: mongoose.connection})
}));
app.use(passport.initialize());
app.use(passport.session());
//connect to DB
mongoose.connect(config.databaseUrl);
User.findOne( {type: 'admin'}, function (err, result) {
if (!result) {
var user = new User();
user.name = 'Super';
user.surname = 'Administrator'
user.school = 'Data Center'
user.email = 'admin@local';
user.local.password = user.generateHash('admin');
user.type = 'admin';
user.save();
console.log('created new admin user (email: admin@local, password: admin)');
}
})
//main config
fs = require ('fs');
//passport config
require("./app/passport")(passport);
//routes
require("./app/routes")(app, passport);
//error handle
app.use((req, res, next) => {
res.redirect('/');
});
app.listen(process.env.PORT||3000, function () {
console.log('Running on port '+(process.env.PORT||3000));
});