fix: ensure typescript routes are hit most to least specific

This commit is contained in:
Andy Burke 2025-06-25 20:24:51 -07:00
parent 4f68a64a88
commit 1928bfcb5e
6 changed files with 35 additions and 12 deletions

View file

@ -16,15 +16,28 @@ Deno.test({
Deno.env.set('SERVERUS_ROOT', './tests/www');
test_server_info = await get_ephemeral_listen_server();
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/echo/hi`, {
method: 'GET'
});
const echoes: Record<string, string> = {
'': 'echo! .... echo. ................... echo?',
hi: 'hello',
yo: 'yo',
'whoa there': 'whoa there'
};
const body = await response.text();
for await (const key of Object.keys(echoes)) {
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/echo/${key}`, {
method: 'GET'
});
asserts.assert(response.ok);
asserts.assert(body);
asserts.assertEquals(body, 'hello');
const body = await response.text();
asserts.assert(response.ok);
asserts.assert(body);
console.dir({
body,
key
});
asserts.assertEquals(body, echoes[key]);
}
} finally {
Deno.env.delete('SERVERUS_ROOT');
if (test_server_info) {

View file

@ -1,5 +1,6 @@
export function GET(_req: Request, meta: Record<string, any>): Response {
return new Response(meta.params.input ?? '', {
const input = decodeURIComponent(meta.params.input ?? '');
return new Response(input, {
status: 200,
headers: {
'Content-Type': 'text/plain'

8
tests/www/echo/index.ts Normal file
View file

@ -0,0 +1,8 @@
export function GET(_req: Request, _meta: Record<string, any>): Response {
return new Response('echo! .... echo. ................... echo?', {
status: 200,
headers: {
'Content-Type': 'text/plain'
}
});
}