Skip to content

Commit

Permalink
Fixed file imports for openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienR1 committed Oct 23, 2023
1 parent 85e6657 commit fd8a180
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const opts = program
.addOption(new Option("--username <string>", "Database user").env("USERNAME").default(DEFAULT_USERNAME))
.addOption(new Option("--password <string>", "Password associated with the specified username").env("PASSWORD").default(DEFAULT_PASSWORD))
.addOption(new Option("--database <string>", "The database to use inside ClickHouse").env("DATABASE").default(DEFAULT_DATABASE))
.addOption(new Option("--create-database <boolean", "If the specified database does not exist, automatically create it").env("CREATE_DATABASE").default(DEFAULT_CREATE_DATABASE))
.addOption(new Option("--create-database <boolean>", "If the specified database does not exist, automatically create it").env("CREATE_DATABASE").default(DEFAULT_CREATE_DATABASE))
.addOption(new Option("--async-insert <number>", "https://clickhouse.com/docs/en/operations/settings/settings#async-insert").choices(["0", "1"]).env("ASYNC_INSERT").default(DEFAULT_ASYNC_INSERT))
.addOption(new Option("--wait-for-async-insert <boolean>", "https://clickhouse.com/docs/en/operations/settings/settings#wait-for-async-insert").choices(["0", "1"]).env("WAIT_FOR_INSERT").default(DEFAULT_WAIT_FOR_ASYNC_INSERT))
.addOption(new Option("--queue-limit <number>","Insert delay to each response when the pqueue exceeds this value").env("QUEUE_LIMIT").default(DEFAULT_QUEUE_LIMIT))
Expand Down
26 changes: 18 additions & 8 deletions src/fetch/GET.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
// @ts-expect-error
import swaggerUI from "../../swagger/index.html";
// @ts-expect-error
import favicon from "../../swagger/favicon.png";

import { file } from "bun";
import { registry } from "../prometheus.js";
import openapi from "./openapi.js";
import health from "./health.js";
import openapi from "./openapi.js";

export default async function (req: Request) {
const { pathname} = new URL(req.url);
const { pathname } = new URL(req.url);

if ( pathname === "/" ) return new Response(Bun.file("./swagger/index.html"));
if ( pathname === "/favicon.png" ) return new Response(Bun.file("./swagger/favicon.png"));
if ( pathname === "/health" ) return health(req);
if ( pathname === "/metrics" ) return new Response(await registry.metrics(), {headers: {"Content-Type": registry.contentType}});
if ( pathname === "/openapi" ) return new Response(openapi, {headers: {"Content-Type": "application/json"}});
if (pathname === "/") return new Response(file(swaggerUI));
if (pathname === "/favicon.png") return new Response(file(favicon));
if (pathname === "/health") return health(req);
if (pathname === "/metrics")
return new Response(await registry.metrics(), {
headers: { "Content-Type": registry.contentType },
});
if (pathname === "/openapi")
return new Response(openapi, { headers: { "Content-Type": "application/json" } });

return new Response("Not found", { status: 400 });
return new Response("Not found", { status: 400 });
}

0 comments on commit fd8a180

Please sign in to comment.