diff --git a/deno.json b/deno.json index 93b4af5..8d49f00 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "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.", - "version": "0.7.0", + "version": "0.7.1", "license": "MIT", "exports": { ".": "./serverus.ts", diff --git a/handlers/html.ts b/handlers/html.ts index aeb545a..ebcf71e 100644 --- a/handlers/html.ts +++ b/handlers/html.ts @@ -25,7 +25,8 @@ async function load_html_with_ssi(html_file: string): Promise { async (_match, type, location, index): Promise => { switch (type) { case 'file': { - const resolved = path.resolve(location); + const directory = path.dirname(html_file); + const resolved = path.resolve(path.join(directory, location)); if (!resolved.startsWith(Deno.cwd())) { console.error( `Cannot include files above the working directory (${Deno.cwd()}): ${location} ${html_file}:${index}` diff --git a/tests/08_test_html_includes.test.ts b/tests/08_test_html_includes.test.ts index ecbc3f7..a1e3a4f 100644 --- a/tests/08_test_html_includes.test.ts +++ b/tests/08_test_html_includes.test.ts @@ -17,7 +17,7 @@ Deno.test({ Deno.chdir('./tests/www'); test_server_info = await get_ephemeral_listen_server(); - const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/`, { + const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/includes/index.html`, { method: 'GET' }); @@ -36,7 +36,7 @@ Deno.test({ }); Deno.test({ - name: 'get html file (text/plain)', + name: 'get html file (text/plain) (also test automatic index.html)', permissions: { env: true, read: true, @@ -51,7 +51,7 @@ Deno.test({ Deno.chdir('./tests/www'); test_server_info = await get_ephemeral_listen_server(); - const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/index.html`, { + const response = await fetch(`http://${test_server_info.hostname}:${test_server_info.port}/includes`, { method: 'GET', headers: { 'Accept': 'text/plain' diff --git a/tests/www/index.html b/tests/www/includes/index.html similarity index 100% rename from tests/www/index.html rename to tests/www/includes/index.html diff --git a/tests/www/another_include.html b/tests/www/includes/subdir/another_include.html similarity index 100% rename from tests/www/another_include.html rename to tests/www/includes/subdir/another_include.html diff --git a/tests/www/includes/test_include.html b/tests/www/includes/test_include.html new file mode 100644 index 0000000..c860e94 --- /dev/null +++ b/tests/www/includes/test_include.html @@ -0,0 +1,3 @@ +
Include #1
+ + diff --git a/tests/www/yet_another_include.html b/tests/www/includes/yet_another_include.html similarity index 100% rename from tests/www/yet_another_include.html rename to tests/www/includes/yet_another_include.html diff --git a/tests/www/test_include.html b/tests/www/test_include.html deleted file mode 100644 index 1218707..0000000 --- a/tests/www/test_include.html +++ /dev/null @@ -1,3 +0,0 @@ -
Include #1
- -