feat: enable dir listing and show dot files in deno code

This commit is contained in:
Huakun Shen 2025-01-29 11:38:49 -05:00
parent d2a05753b3
commit 796640961e
No known key found for this signature in database
3 changed files with 9 additions and 7 deletions

View File

@ -4,10 +4,12 @@ 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
fsRoot: path,
showDirListing: true,
showDotfiles: true,
quiet: true
});
});
console.error('Server started at port', path, server.addr.port);

View File

@ -6,7 +6,7 @@
// let isDragging = false;
let { onSubmit }: { onSubmit: (path: string, port: number) => void } = $props();
let path = $state('');
let port = $state(0);
let port = $state(8000);
onMount(() => {
// event.onDragEnter(() => {

View File

@ -23,7 +23,7 @@
}
getRpcAPI()
.then((rpc) => {
.then((rpc) =>
rpc.api.serve(path, port).then((realPort) => {
jobsStore.addJob({
path,
@ -31,11 +31,11 @@
process: rpc.process
});
toast.success('Server started');
});
})
)
.catch((err) => {
toast.error('Failed to serve', {
description: err.message
description: `${err.message}; consider changing the port`
});
});
}