Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const handleConfig = (res: any): void => {
* @param res The HTTP response object.
* @param options Server configuration options.
*/
export const routeRequest = (req: any, res: any, options: ServerOptions): void => {
export const routeRequest = async (req: any, res: any, options: ServerOptions): Promise<void> => {
const url = req.url ?? '';
const method = req.method ?? 'GET';

Expand All @@ -132,7 +132,7 @@ export const routeRequest = (req: any, res: any, options: ServerOptions): void =
}

if (method === 'POST' && url === '/analyze') {
handleAnalyze(req, res, options);
await handleAnalyze(req, res, options);
return;
}

Expand All @@ -148,8 +148,12 @@ export const routeRequest = (req: any, res: any, options: ServerOptions): void =
export async function createServer(options: ServerOptions): Promise<{ close: () => void; port: number }> {
const { createServer: createHttpServer } = await import('node:http');

const server = createHttpServer((req, res) => {
routeRequest(req, res, options);
const server = createHttpServer(async (req, res) => {
try {
await routeRequest(req, res, options);
} catch (error) {
sendJson(res, 500, { error: (error as Error).message });
}
});

return new Promise((resolve) => {
Expand Down
Loading