fix: better handling of .spa file being in the root, improved code
path
This commit is contained in:
parent
474d455986
commit
1220f1a370
3 changed files with 11 additions and 15 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@andyburke/serverus",
|
"name": "@andyburke/serverus",
|
||||||
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
|
"description": "A flexible HTTP server for mixed content. Throw static files, markdown, Typescript and (hopefully, eventually) more into a directory and serverus can serve it up a bit more like old-school CGI.",
|
||||||
"version": "0.14.1",
|
"version": "0.14.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./serverus.ts",
|
".": "./serverus.ts",
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,7 @@ async function find_spa_file_root(request_path: string): Promise<string | undefi
|
||||||
const relative_path = path.relative(current_path, request_path);
|
const relative_path = path.relative(current_path, request_path);
|
||||||
const path_elements = relative_path.split('/').slice(0, -1);
|
const path_elements = relative_path.split('/').slice(0, -1);
|
||||||
|
|
||||||
let element;
|
do {
|
||||||
|
|
||||||
while ((element = path_elements.shift())) {
|
|
||||||
current_path = path.join(current_path, element);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const spa_file_stat = await Deno.stat(path.join(current_path, '.spa'));
|
const spa_file_stat = await Deno.stat(path.join(current_path, '.spa'));
|
||||||
|
|
||||||
|
|
@ -25,14 +21,14 @@ async function find_spa_file_root(request_path: string): Promise<string | undefi
|
||||||
return current_path;
|
return current_path;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Deno.errors.NotFound) {
|
if (!(error instanceof Deno.errors.NotFound)) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_path = path.join(current_path, path_elements.shift() ?? '');
|
||||||
|
} while (path_elements.length);
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ Deno.test({
|
||||||
const cwd = Deno.cwd();
|
const cwd = Deno.cwd();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Deno.chdir('./tests/www');
|
Deno.chdir('./tests/www/spa');
|
||||||
test_server_info = await get_ephemeral_listen_server();
|
test_server_info = await get_ephemeral_listen_server();
|
||||||
|
|
||||||
{
|
{
|
||||||
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/foo/bar/baz`, {
|
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/foo/bar/baz`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ Deno.test({
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/testing`, {
|
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/testing`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ Deno.test({
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/spa/testing/blah.html`, {
|
const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/testing/blah.html`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue