-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
89 lines (78 loc) · 2.37 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
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const morgan = require("morgan");
const logger = require("./config/winston");
const fileUpload = require("express-fileupload");
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerDefinition = {
openapi: '3.0.1',
info: {
title: 'Phenoflow API',
version: '1.0.0',
description:
'Test the endpoints offered by Phenoflow.'
},
servers: [
{
url: 'http://localhost:3003',
description: 'Development server',
},
{
url: 'https://localhost:3003',
description: 'Secure development server',
},
{
url: 'https://kclhi.org',
description: 'Live server',
}
],
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
}
}
}
};
const options = {
swaggerDefinition,
apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJSDoc(options);
const swaggerUi = require('swagger-ui-express');
require('dotenv').config()
const login = require("./routes/login");
const implementation = require("./routes/implementation");
const importer = require("./routes/importer");
const app = express();
app.enable('strict routing');
app.use(morgan("combined", {stream:logger.stream}));
app.use(bodyParser.json({extended:false, limit:'50mb'}));
app.use(bodyParser.urlencoded({limit:'50mb', extended:false, parameterLimit:50000}));
app.use(cookieParser());
const router = express.Router();
router.use("/login", login);
router.use(fileUpload({createParentPath:true}));
router.use("/implementation", implementation);
router.use("/importer", importer);
router.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use("/phenoflow", router);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
logger.error(`${err.status || 500} - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`);
// render the error page
res.status(err.status || 500);
});
module.exports = app;