|
1 | | -import * as bodyParser from "body-parser"; |
2 | | -import * as express from "express"; |
3 | | -import * as logger from "morgan"; |
4 | | -import * as path from "path"; |
5 | | -import rfs from "rotating-file-stream"; |
6 | | -import route from "./server/routes"; |
7 | | -// import * as swaggerDocument from "./server/swagger.json" |
8 | | - |
9 | | -export const env: string = process.env.NODE_ENV || "development"; |
10 | | -export const rpcServer: string = require(`${__dirname}/server/config/dex.json`).node[ |
11 | | - env |
12 | | -].rpc; |
13 | | - |
14 | | -// Set up the express app |
15 | | -const app = express(); |
16 | | - |
17 | | -// Log requests to the console. |
18 | | -app.use(logger("dev")); |
19 | | - |
20 | | -// create a rotating write stream |
21 | | -const accessLogStream = rfs("access.log", { |
22 | | - interval: "1d", // rotate daily |
23 | | - path: path.join(__dirname, "log") |
24 | | -}); |
25 | | - |
26 | | -// setup the logger |
27 | | -app.use(logger("combined", { stream: accessLogStream })); |
28 | | - |
29 | | -// Parse incoming requests data (https://github.com/expressjs/body-parser) |
30 | | -app.use(bodyParser.json()); |
31 | | -app.use(bodyParser.urlencoded({ extended: false })); |
32 | | - |
33 | | -const cors = require("cors"); |
34 | | -app.use(cors()); |
35 | | -// Setup a default catch-all route that sends back a welcome message in JSON format. |
36 | | -route(app); |
37 | | - |
38 | | -const swaggerJsdoc = require('swagger-jsdoc'); |
39 | | - |
40 | | -const options = { |
41 | | - swaggerDefinition: { |
42 | | - info: { |
43 | | - title: 'Test API', |
44 | | - version: '1.0.0', |
45 | | - description: 'Test Express API with autogenerated swagger doc', |
46 | | - }, |
47 | | - }, |
48 | | - // List of files to be processes. You can also set globs './routes/*.ts' |
49 | | - apis: ['./server/routes/order.ts', './server/routes/deal.ts', './server/routes/index.ts'], |
50 | | -}; |
51 | | - |
52 | | -const specs = swaggerJsdoc(options); |
53 | | - |
54 | | - |
55 | | -const swaggerUi = require('swagger-ui-express'); |
56 | | -app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs)); |
57 | | - |
58 | | -export default app; |
| 1 | +import * as bodyParser from "body-parser"; |
| 2 | +import * as express from "express"; |
| 3 | +import * as logger from "morgan"; |
| 4 | +import * as path from "path"; |
| 5 | +import rfs from "rotating-file-stream"; |
| 6 | +import route from "./server/routes"; |
| 7 | + |
| 8 | +// Set up the express app |
| 9 | +const app = express(); |
| 10 | + |
| 11 | +// Log requests to the console. |
| 12 | +app.use(logger("dev")); |
| 13 | + |
| 14 | +// create a rotating write stream |
| 15 | +const accessLogStream = rfs("access.log", { |
| 16 | + interval: "1d", // rotate daily |
| 17 | + path: path.join(__dirname, "log") |
| 18 | +}); |
| 19 | + |
| 20 | +// setup the logger |
| 21 | +app.use(logger("combined", { stream: accessLogStream })); |
| 22 | + |
| 23 | +// Parse incoming requests data (https://github.com/expressjs/body-parser) |
| 24 | +app.use(bodyParser.json()); |
| 25 | +app.use(bodyParser.urlencoded({ extended: false })); |
| 26 | + |
| 27 | +const cors = require("cors"); |
| 28 | +app.use(cors()); |
| 29 | +// Setup a default catch-all route that sends back a welcome message in JSON format. |
| 30 | +route(app); |
| 31 | + |
| 32 | +const swaggerJsdoc = require('swagger-jsdoc'); |
| 33 | + |
| 34 | +const options = { |
| 35 | + swaggerDefinition: { |
| 36 | + info: { |
| 37 | + title: 'CodeChain-Exchange API', |
| 38 | + version: '1.0.0', |
| 39 | + description: 'CodeChain-Exchange Express API with autogenerated swagger doc', |
| 40 | + }, |
| 41 | + }, |
| 42 | + // List of files to be processes. You can also set globs './routes/*.ts' |
| 43 | + apis: ['./server/routes/order.ts', './server/routes/deal.ts', './server/routes/index.ts'], |
| 44 | +}; |
| 45 | + |
| 46 | +const specs = swaggerJsdoc(options); |
| 47 | + |
| 48 | + |
| 49 | +const swaggerUi = require('swagger-ui-express'); |
| 50 | +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs)); |
| 51 | + |
| 52 | +export default app; |
0 commit comments