-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.js
60 lines (52 loc) · 2 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
const express = require('express')
const bodyParser = require('body-parser')
const path = require('path')
require('./config/config.js')
const app = express()
var allowCrossDomain = function (req, res, next) {
var devAllowedOrigins = ['http://localhost:3000', 'https://miteb-stage.cribblservices.com']
var prodAllowedOrigins = ['https://miteb-prod.cribblservices.com']
var allowedOrigins = process.env.NODE_ENV === 'production' ? prodAllowedOrigins : devAllowedOrigins
var origin = req.headers.origin
if (allowedOrigins.indexOf(origin) > -1) {
res.setHeader('Access-Control-Allow-Origin', origin)
}
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
res.header('Access-Control-Allow-Headers', 'Content-Type')
next()
}
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(allowCrossDomain)
app.set('view engine', 'ejs')
app.use(express.static(path.join(__dirname, '/public')))
app.use(function (req, res, next) {
// console.log(req.headers)
if (process.env.NODE_ENV === 'production' && (req.headers.origin !== 'https://miteb-prod.cribblservices.com')) {
res.status(503).send('Unauthorized')
} else if (process.env.NODE_ENV === 'development' && (req.headers.origin !== 'https://miteb-stage.cribblservices.com')) {
// res.status(503).send("Unauthorized");
// return;
next()
} else {
next()
}
})
app.get('/', function (req, res) {
res.send(`This is the ${app.settings.env} server`)
// res.render('test')
})
app.get('/', function (req, res) {
res.render('test')
})
var userRoutes = require('./routes/user')
var eventRoutes = require('./routes/event')
var notifRoutes = require('./routes/notif')
var complaintsRoutes = require('./routes/complaints')
app.use('/user', userRoutes)
app.use('/event', eventRoutes)
app.use('/notif', notifRoutes)
app.use('/complaint', complaintsRoutes)
app.listen(process.env.PORT || 9000, function () {
console.log('Express server listening on port %d in %s mode', this.address().port, app.settings.env)
})