mirror of
https://github.com/kunkunsh/kunkun-ext-serve.git
synced 2025-04-03 18:16:42 +00:00
17 lines
511 B
TypeScript
17 lines
511 B
TypeScript
import { expose } from '@kunkun/api/runtime/deno';
|
|
import { serveDir } from 'jsr:@std/http/file-server';
|
|
import type { API } from '../src/api.types.ts';
|
|
|
|
expose({
|
|
serve: (path: string, port: number): Promise<number> => {
|
|
// const port2 = port ?? findFreePort();
|
|
const server = Deno.serve({ port }, (req: Request) => {
|
|
return serveDir(req, {
|
|
fsRoot: path
|
|
});
|
|
});
|
|
console.error('Server started at port', path, server.addr.port);
|
|
return Promise.resolve(server.addr.port);
|
|
}
|
|
} satisfies API);
|