-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.js
86 lines (62 loc) · 2.29 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
/**
* Created by tech4GT on 8/25/17.
*/
const config = require('./config')
if (config.DEPLOY_CONFIG !== 'localhost') {
const nr = require('newrelic')
const Raven = require('raven');
Raven.config(config.SENTRY_DSN).install();
}
const express = require('express');
const app = express();
const bp = require('body-parser')
const passport = require('passport')
const debug = require('debug')('schedulecture:server')
const sequelize = require('./db/models').DATABASE;
app.use(bp.json())
app.use(bp.urlencoded({extended: true}));
const api_v1 = require('./routes/api_v1');
const users = require('./routes/users');
app.use(passport.initialize());
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");
next();
});
//app.use(passport.session());
app.use('/', express.static(__dirname + "/public_html"));
/*app.get('/checkAdmin', (req, res, next) => {
passport.authenticate('bearer', (err, user, info) => {
if (err) { return res.status(500).json({success: false}) }
if (!user) { return res.status(401).json({success: false}) }
req.logIn(user, function(err) {
if (err) { res.status(500).json({success: false}) }
return res.status(200).json({success: true});
});
})(req, res, next)
});*/
app.get('/checkAdmin', passport.authenticate('bearer', {failWithError: true}),
function (req, res, next) {
// Handle success
if (req.user)
return res.status(200).json({success: true});
},
function (err, req, res, next) {
// Handle error
return res.status(401).json({success: false});
}
);
app.use('/admin/centres/:id/rooms', express.static(__dirname + "/public_html/admin/centres/rooms"));
app.use('/admin/batches/:id/lectures', express.static(__dirname + "/public_html/admin/batches/lectures"));
app.use('/docs', express.static(__dirname + "/docs"));
app.use('/api/v1', api_v1)
app.use('/users', users)
// app.use('/bower_components', express.static(__dirname + "/bower_components"));
sequelize.sync({
force: process.env.SCHEDULECTURE_FORCE_DB_RECREATE || false,
}).then(function () {
debug("Database Configured");
app.listen(process.env.PORT || 4000, function () {
debug(`Server listening at ` + (process.env.PORT || 4000));
});
});