feature: serverus modularly serves up a directory as an HTTP server
This commit is contained in:
commit
58139b078d
20 changed files with 1449 additions and 0 deletions
22
tests/handlers/foo.ts
Normal file
22
tests/handlers/foo.ts
Normal 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'
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue