-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
70 lines (58 loc) · 1.9 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
const express = require('express')
const path = require('path')
var bodyParser = require('body-parser');
const cookieParser = require("cookie-parser");
const csrf = require("csurf");
var { admin } = require('./firebase');
const csrfMiddleware = csrf({ cookie: true });
const connection = require('./models');
const PORT = 3000
//Requiring Routes.
const loginRouter = require('./routes/login')
const homeRouter = require('./routes/home')
const profileRouter = require('./routes/profile')
const hierarchyRouter = require('./routes/hierarchy')
const crthierarchyRouter = require('./routes/crthierarchy')
const datasetRouter = require('./routes/dataset')
const expertsRouter = require('./routes/experts')
const aboutRouter = require('./routes/about')
// Initializing app
const app = express();
// Setting up our view engine and static files
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use('/static', express.static('public'));
// Parses the body for POST, PUT, DELETE, etc.
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(bodyParser.raw());
// cookie parser and csrf middleware
app.use(cookieParser());
app.use(csrfMiddleware);
// intercept all requests and verify csrf token
app.all("*", (req, res, next) => {
res.cookie("XSRF-TOKEN", req.csrfToken());
next();
});
// Telling express to use Routes
app.use('/',loginRouter);
app.use('/',homeRouter);
app.use('/',profileRouter);
app.use('/',hierarchyRouter);
app.use('/',datasetRouter);
app.use('/',crthierarchyRouter);
app.use('/',expertsRouter);
app.use('/',aboutRouter);
// seting admin custom claims
var admin_uids = ["HcKl749xNfbvZrMDveQh2Zu5LbN2"];
var uid;
for(uid=0; uid<admin_uids.length; uid ++){
admin.auth().setCustomUserClaims(admin_uids[uid], {
user: true,
expert: true,
admin: true
});
}
app.listen(PORT, () => {
console.log(`App listening at http://localhost:${PORT}`)
})