-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
46 lines (36 loc) · 1.15 KB
/
server.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
import { Hono } from "hono";
import { logger } from "hono/logger";
import * as path from "path";
import { cors } from "hono/cors";
import { getRouterName, showRoutes } from "hono/dev";
import * as dotenvx from "@dotenvx/dotenvx";
dotenvx.config();
import { serve, type HttpBindings } from "@hono/node-server";
import { absolutePath } from "swagger-ui-dist";
import { serveStatic } from "@hono/node-server/serve-static";
const app = new Hono();
app.use(logger());
const pathToSwaggerUi = absolutePath();
const relativatePath = path.relative(process.cwd(), pathToSwaggerUi);
app
.use(
"/openapi.yaml",
cors({
origin: "http://localhost:4000",
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
allowMethods: ["POST", "GET", "OPTIONS"],
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
maxAge: 600,
credentials: false,
}),
)
.get("/openapi.yaml", serveStatic({ root: "./" }));
showRoutes(app, {
verbose: true,
});
console.log(`pathToSwaggerUi contains ${relativatePath}`);
app.use("/*", serveStatic({ root: `${relativatePath}/` }));
export default serve({
fetch: app.fetch,
port: 4000,
});