feature: serverus modularly serves up a directory as an HTTP server

This commit is contained in:
Andy Burke 2025-06-19 15:43:01 -07:00
commit 58139b078d
20 changed files with 1449 additions and 0 deletions

22
tests/handlers/foo.ts Normal file
View file

@ -0,0 +1,22 @@
import * as path from '@std/path';
/**
* Any request that is for something with the extension 'foo' should return 'foo'
*
* @param request The incoming HTTP request
* @returns Either a response (a foo) or undefined if unhandled.
*/
export default function handle_static_files(request: Request): Response | undefined {
const url: URL = new URL(request.url);
const extension: string = path.extname(url.pathname)?.slice(1)?.toLowerCase() ?? '';
if (extension !== 'foo') {
return;
}
return new Response('foo', {
status: 200,
headers: {
'Content-Type': 'text/plain'
}
});
}