-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
63 lines (50 loc) · 1.38 KB
/
index.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
const express = require('express');
const cors = require('cors');
const logger = require('morgan');
const expressJSDocSwagger = require('express-jsdoc-swagger');
const app = express();
const middlewares = require('./src/middlewares');
const db = require('./src/db');
// connectors for db, cache etc.;
async function connector() {
await db.MongoDB.connector();
}
connector();
const port = 7979;
app.use(cors());
app.use(logger('dev'));
app.use(express.json({ limit: 1000000 }));
app.use(express.urlencoded({ extended: false }));
expressJSDocSwagger(app)(middlewares.swagger);
app.use(express.json({ limit: '50mb' }));
//routes;
app.use(require('./src/routes'));
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
console.error(err);
let response = {
status: false,
desc: '',
httpStatus: 500
};
response.desc = err.message;
return res.status(response.httpStatus).send(response); // Bad request
}
return next();
});
/**
* 404
*/
app.use(function (req, res) {
let response = {
httpStatus: 404,
status: false
};
response.desc = 'No endpoint!';
return res.status(response.httpStatus).json(
response
);
});
app.listen(port, () => {
console.log(`Kandilli Rasathanesi API Service API - PORT: ${port}`);
});