-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (38 loc) · 1.4 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
//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.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' }))
//Allow server side request
var cors = require('cors')
app.use(cors());
// var db = require('./config/db')
// db.setupDatabase()
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)
// if (!isUserPostRoute) {
// jwtHelper.verifyJsonWebToken(req,res,next,app)
// }
next()
})
//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)
})