-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.ts
76 lines (64 loc) · 1.72 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as dotenv from 'dotenv'
import express from "express";
import path from "path";
import cookieParser from "cookie-parser";
import logger from "morgan";
import { initialize } from "express-openapi";
import swaggerUi from "swagger-ui-express";
import ApiDocs from "./api/api-doc.json"
import bodyParser from "body-parser";
import cors from "cors";
import {addContextMiddle} from "./api/addContextMiddle"
import { createProxyMiddleware } from 'http-proxy-middleware'
declare namespace Express {
export interface Request {
context?: object
}
}
var app = express();
app.use(cors())
// the path is for the builded javascript version
dotenv.config({ path: __dirname+'/../.env' });
app.use('/:prefix/api',
createProxyMiddleware({
target: process.env.SERVER_ENDPOINT || "http://localhost:6363",
changeOrigin: false,
// onProxyRes: onProxyRes,
pathRewrite: {
'^/.*/api': '/api' // remove base path
},
secure: false
}))
app.use(bodyParser.json());
// OpenAPI routes
initialize({
app,
// @ts-ignore
apiDoc: ApiDocs,//"./api/api-doc.json",//require("./api/api-doc"),
paths: path.resolve(__dirname, 'api/paths')
});
// OpenAPI UI
app.use(
"/api-documentation",
swaggerUi.serve,
swaggerUi.setup(undefined, {
swaggerOptions: {
url: "http://localhost:3035/api-docs",
/*basicAuth: {
name: 'Authorization',
schema: {
type: 'basic',
in: 'header'
},
value: 'Basic <user:password>'
} */
},
})
);
app.use(addContextMiddle)
app.listen(3035);
console.log("App running on port http://localhost:3035");
console.log(
"OpenAPI documentation available in http://localhost:3035/api-documentation"
);
//module.exports = app;