-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
93 lines (78 loc) · 2.04 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const uuid = require('node-uuid');
const morgan = require('morgan');
const {
configureNoUserScope
} = require('./services/sentry');
const app = express();
const corsOption = {
origin: true,
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
exposedHeaders: ['x-auth-token']
};
app.use(cors(corsOption));
app.use(express.json({limit: '100mb'}));
app.use(express.urlencoded({ extended: false, limit: '100mb' }));
///////////////////////////
// Logging
///////////////////////////
configureNoUserScope();
// const loggerFormat = '(:user-agent) :method :url :status :res[content-length] - :response-time ms';
const loggerFormat = 'dev';
const assignId = (req, res, next) => {
req.id = uuid.v4();
next();
};
app.use(assignId);
app.use(morgan(loggerFormat, {
skip: function (req, res) {
return res.statusCode < 400
},
stream: process.stderr
}));
app.use(morgan(loggerFormat, {
skip: function (req, res) {
return res.statusCode >= 400
},
stream: process.stdout
}));
///////////////////////////
// Routes
///////////////////////////
const {
homeRouter,
statusRouter,
verificationRouter,
loginRouter,
logoutRouter,
usersRouter,
meRouter,
kycRouter,
songsRouter,
genresRouter,
webhooksRouter,
testRouter
} = require('./routes');
app.use('/', homeRouter);
app.use('/status', statusRouter);
app.use('/verification', verificationRouter);
app.use('/login', loginRouter);
app.use('/logout', logoutRouter);
app.use('/users', usersRouter);
app.use('/me', meRouter);
app.use('/kyc', kycRouter);
app.use('/songs', songsRouter);
app.use('/genres', genresRouter);
app.use('/webhooks', webhooksRouter);
app.use('/test', testRouter);
app.use(function (err, req, res, next) {
res.status(400).json(err);
});
//////////////////////////////////////////
// Connecting to database
//////////////////////////////////////////
require('./db/mongoose').connect();
module.exports = app;