-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
31 lines (28 loc) · 998 Bytes
/
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
import express from "express";
import { expressLogger } from "./middleware/logger.js";
import swaggerUiExpress from "swagger-ui-express";
import sse from "./api/sse.js";
import helloRouter from "./api/hello.js";
import { corsMiddleware } from "./middleware/cors.js";
import apiConfig from "./swagger/apiconfig.js";
import { resolve } from "path";
import fs from "node:fs/promises";
const { BASEPATH, swaggerUIPath, swaggerJSONPath } = apiConfig;
// or use node.js 17+: import doc from './swagger-output.json' assert { type: 'json' };
const swaggerSpec = JSON.parse(await fs.readFile(swaggerJSONPath));
const app = express();
app.use(expressLogger);
const router = express.Router();
router.use(express.json());
router.use(corsMiddleware);
// API Router
router.use(helloRouter);
router.get("/sse", sse);
router.use(
swaggerUIPath,
swaggerUiExpress.serve,
swaggerUiExpress.setup(swaggerSpec),
);
app.use(BASEPATH, router);
app.use("/", express.static(resolve("public")));
export default app;