forked from bikedeboa/bikedeboa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (61 loc) · 1.98 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
71
let express = require('express')
let methodOverride = require('method-override')
let bodyParser = require('body-parser')
let cors = require('cors')
let app = express()
let path = require('path')
let swig = require('swig')
let acl = require('express-acl')
let helmet = require('helmet')
let compression = require('compression')
// server config
app.use(methodOverride('X-HTTP-Method'))
app.use(methodOverride('X-HTTP-Method-Override'))
app.use(methodOverride('X-Method-Override'))
app.use(methodOverride('_method'))
app.use(bodyParser.json({limit: '50mb'}))
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }))
app.use(helmet())
app.use(cors({
// origin: ['https://www.bikedeboa.com.br','https://bikedeboa-dev.herokuapp.com','https://bikedeboa-dev2.herokuapp.com'],
origin: [true],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'x-access-token', 'ip_origin']
}))
app.use(compression())
// static
app.use(express.static(path.join(__dirname, 'public')))
// setup swig
app.set('view engine', 'html')
app.set('views', path.join(__dirname, 'views'))
app.engine('html', swig.renderFile)
// setup acl
acl.config({
baseUrl: '/',
filename: 'acl.json',
path: 'config'
})
// skip favicon
app.use(function (request, response, next) {
if (request.url === '/favicon.ico') {
response.writeHead(200, {'Content-Type': 'image/x-icon'})
response.end('')
} else {
next()
}
})
// router
app.use('/', require('./routes'))
// error handling
app.use(function (request, response, next) {
var err = new Error('Not Found')
err.status = 404
next(err)
})
app.use(function (err, request, response, next) {
response.status(err.status || 500).json({ error: err.errors || err.message })
})
// server listener
module.exports = app
// start api: export DEBUG=api:* && export JWT_TKN_SECRET=testBdb && export NODE_ENV=development && export SUPPRESS_NO_CONFIG_WARNING=false && npm run nodemon
// see fixes pattern code: standard 'app.js' 'routes/*.js' 'controllers/*.js'