-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
67 lines (47 loc) · 1.81 KB
/
Copy pathserver.js
File metadata and controls
67 lines (47 loc) · 1.81 KB
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
//server.js
//BASE SETUP
// =============================================================================================================================
var express = require('express')
var app = express()
process.env.NODE_ENV = app.get('env') //set node env
var environment = require('./config/environment') // get our config file
//Configure app to user bodyParse()
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(bodyParser.json({ type: 'application/*+json' }))
app.use(bodyParser.raw({ type: 'application/vnd.api+json' }))
app.use(bodyParser.json({ type: 'application/*+json' }))
// app.use(bodyParser.raw({ type: 'text/html' }))
//Allow server side request
var cors = require('cors')
app.use(cors());
var swaggerSetup = require('./config/swagger-setup')
swaggerSetup.setupSwagger(app, express)
app.set('superSecret', environment.secret) // secret variable
var jwtHelper = require('./lib/jwthelper')
app.use(function (req, res, next) {
var isUserPostRoute = ((req.path.indexOf('users') > -1 && req.method === 'POST') || req.path.indexOf('auth') > -1)
var appMainToken = req.headers['main-token']
if (appMainToken == 'ZRCNAamAQ$yTv6&2VQ4eR*f?437w[FkF/gktDTg6#GunNQuE8@#]MC9B3NBTxifH') {
if (!isUserPostRoute) {
jwtHelper.verifyJsonWebToken(req, res, next, app)
} else {
next()
}
} else {
res.status(403).send({"error":"unauthorized"})
}
})
//Format debug log
var morgan = require('morgan')
app.use(morgan('dev'))
var routesSetup = require('./config/routes')
routesSetup.setupRoutesAndVersions(app)
module.exports = app
//Service setup
var port = process.env.PORT || 8080
app.listen(port, function () {
console.log('Now is running on port' + port)
})