forked from pinks/eris
1
0
Fork 0
nyx/api/mod.ts

28 lines
850 B
TypeScript

import { route } from "reroute";
import { serveSpa } from "serve_spa";
import { api } from "./serveApi.ts";
import { fromFileUrl } from "std/path/mod.ts";
// New function that handles the webhook
import { handleWebhook } from "../bot/mod.ts";
export async function serveUi() {
const server = Deno.serve({ port: 8443 }, (request) =>
route(request, {
"/api/*": (request) => api.fetch(request),
"/webhook": handleWebhook, // Create the webhook route handle
"/*": (request) =>
serveSpa(request, {
fsRoot: fromFileUrl(new URL("../ui/", import.meta.url)),
indexFallback: true,
importMapFile: "../deno.json",
aliasMap: {
"/utils/*": "../utils/",
},
log: (_request, response) => response.status >= 400,
}),
}));
await server.finished;
}