-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (41 loc) · 1.42 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
const express = require('express');
const bodyParser = require('body-parser')
const path = require('path');
const cookieParser = require('cookie-parser');
const config = require('./config')
const mongodb = require('./datasource/mongodb')
const logger = require('./middleware/logger');
const directories = require('./endpoints/directories/routes');
const files = require('./endpoints/files/routes');
const images = require('./endpoints/images/routes');
const userFilePermissions = require('./endpoints/user-file-permissions/routes');
const users = require('./endpoints/users/routes');
const components = require('./endpoints/components/routes')
const app = express();
// middleware: logger
app.use(logger);
// middleware: body parser
app.use(bodyParser.json({limit: '100MB'}));
app.use(bodyParser.urlencoded({extended: true}));
// endpoints
app.use('/directories', directories);
app.use('/files', files);
app.use('/images', images);
app.use('/user-file-permissions', userFilePermissions);
app.use('/users', users);
app.use('/components', components)
// handle next(error) calls
app.use((info, req, res, next) => {
const { status, message } = info
console.error(JSON.stringify(info, null, 2))
res.status(status).send(message)
})
// start listening
start = async () => {
await mongodb.connect()
console.log('Connected to database')
app.listen(config.port, () => {
console.log(`Listening on port: ${config.port}`)
})
}
start()