-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
69 lines (51 loc) · 1.72 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
'use strict'
global.__basedir = __dirname
require('dotenv-extended').load()
// ---------------------------------------------------------------------------------------
// Packages
const express = require('express')
const consign = require('consign')
const mongoose = require('mongoose')
const cors = require('cors')
// ---------------------------------------------------------------------------------------
// App Express
const app = express()
// Cors
app.use(cors())
// ---------------------------------------------------------------------------------------
// Middlewares
app.use(express.json())
// ---------------------------------------------------------------------------------------
if (process.env.MONGO_STRING_CONNECTION) {
mongoose.connect(process.env.MONGO_STRING_CONNECTION, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
}
// ---------------------------------------------------------------------------------------
// Load packages with consign
consign({ cwd: 'app' })
.include('models')
.then('helpers')
.then('controllers')
.then('services')
.then('middlewares')
.then('routes')
.into(app)
// ---------------------------------------------------------------------------------------
// Catch not found and forward to error handler
app.use((req, res) => {
res.status(500).json({
error: 'Not found',
url: req.url,
method: req.method,
query: req.query,
params: req.params,
statusCode: req.statusCode,
statusMessage: req.statusMessage
})
})
// ---------------------------------------------------------------------------------------
module.exports = app