-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
103 lines (88 loc) · 2.24 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
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
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const MongoStore = require("connect-mongo");
const session = require("express-session");
const apiRouter = require('./api');
const config = require('./config/config.js');
import login, { passport } from './app/routes/login';
const server = express();
server.use(express.json({
type: ['application/json', 'text/plain']
}))
// Database Connection
mongoose.connect(config.mongodb.dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(console.log("MongoDB Connected"));
// View Engine Setup
server.set('view engine', 'ejs');
// Middleware
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({
extended: true
}));
server.use(express.static('public'));
// Models
const Accomodation = require('./app/models/Accomodation');
const Event = require('./app/models/Event');
const Registration = require('./app/models/Registration');
const Tour = require('./app/models/Tour');
const Tshirt = require('./app/models/Tshirt');
const User = require('./app/models/Users');
// Express Session
server.use(
session({
store: MongoStore.create({mongoUrl: config.mongodb.dbURI}),
secret: "texy",
resave: false,
saveUninitialized: true,
})
);
// Passport Middleware
server.use(passport.initialize());
server.use(passport.session());
// Routes
server.get(['/',
'/login',
'/accomodation',
'/event-participation',
'/tshirt',
'/tours',
'/previews',
'/report/registered',
'/report/summary',
'/report/tshirt',
'/report/participation',
'/report/totalcost',
'/report/paymentstatus',
'/report/balance',
'/test',
], (req, res) => {
res.render('index');
});
server.get('/dbtest', (req, res) => {
let user = new User({
username: "testUsername2",
password: "testPassword2",
isAdmin: true
});
console.log(user);
user.save();
res.send("Done!");
});
server.get('/dbclear', (req, res) => {
User.deleteMany({}).then(() => {
res.send("Done!");
}).catch(() => {
res.send("Error!");
});
});
server.use('/api', apiRouter);
server.use('/login', login);
server.get('*', (req, res) => {
res.render('index');
})
server.listen(config.port, () => {
console.info('Express listening on port 8080', config.port);
});