-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.ts
52 lines (40 loc) · 1.43 KB
/
app.ts
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
import * as bodyParser from "body-parser";
import * as express from "express";
import * as logger from "morgan";
import * as path from "path";
import rfs from "rotating-file-stream";
import route from "./server/routes";
// Set up the express app
const app = express();
// Log requests to the console.
app.use(logger("dev"));
// create a rotating write stream
const accessLogStream = rfs("access.log", {
interval: "1d", // rotate daily
path: path.join(__dirname, "log")
});
// setup the logger
app.use(logger("combined", { stream: accessLogStream }));
// Parse incoming requests data (https://github.com/expressjs/body-parser)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const cors = require("cors");
app.use(cors());
// Setup a default catch-all route that sends back a welcome message in JSON format.
route(app);
const swaggerJsdoc = require('swagger-jsdoc');
const options = {
swaggerDefinition: {
info: {
title: 'CodeChain-Exchange API',
version: '1.0.0',
description: 'CodeChain-Exchange Express API with autogenerated swagger doc',
},
},
// List of files to be processes. You can also set globs './routes/*.ts'
apis: ['./server/routes/order.ts', './server/routes/deal.ts', './server/routes/index.ts'],
};
const specs = swaggerJsdoc(options);
const swaggerUi = require('swagger-ui-express');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
export default app;