Elffuss BraidHub

kikocis/continue public

main · 1.1 KiBRawPermalink
1// This is a simple Express server to serve Swagger UI
2import express from "express";
3import fs from "fs";
4import yaml from "js-yaml";
5import path from "path";
6import swaggerUi from "swagger-ui-express";
7import { fileURLToPath } from "url";
8
9// ES Module handling for __dirname
10const __filename = fileURLToPath(import.meta.url);
11const __dirname = path.dirname(__filename);
12
13// Read the OpenAPI spec
14const openApiYaml = fs.readFileSync(
15 path.join(__dirname, "openapi.yaml"),
16 "utf8",
17);
18const openApiSpec = yaml.load(openApiYaml);
19
20const app = express();
21const port = process.env.PORT || 3002;
22
23// Serve the Swagger UI at the root URL
24app.use(
25 "/",
26 swaggerUi.serve,
27 swaggerUi.setup(openApiSpec, {
28 explorer: true,
29 customCss: ".swagger-ui .topbar { display: none }",
30 swaggerOptions: {
31 docExpansion: "list", // or 'full' or 'none'
32 filter: true,
33 showExtensions: true,
34 showCommonExtensions: true,
35 },
36 }),
37);
38
39// Start the server
40app.listen(port, () => {
41 console.log(`Swagger UI is running at http://localhost:${port}`);
42 console.log(`Press Ctrl+C to stop the server`);
43});