summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/integrations/node/src/serve-static.ts24
-rw-r--r--packages/integrations/node/test/trailing-slash.js31
2 files changed, 27 insertions, 28 deletions
diff --git a/packages/integrations/node/src/serve-static.ts b/packages/integrations/node/src/serve-static.ts
index a88b1332f..b0b1e1766 100644
--- a/packages/integrations/node/src/serve-static.ts
+++ b/packages/integrations/node/src/serve-static.ts
@@ -32,31 +32,29 @@ export function createStaticHandler(app: NodeApp, options: Options) {
const hasSlash = urlPath.endsWith('/');
switch (trailingSlash) {
- case "never":
- if (isDirectory && (urlPath != '/') && hasSlash) {
- pathname = urlPath.slice(0, -1) + (urlQuery ? "?" + urlQuery : "");
+ case 'never':
+ if (isDirectory && urlPath != '/' && hasSlash) {
+ pathname = urlPath.slice(0, -1) + (urlQuery ? '?' + urlQuery : '');
res.statusCode = 301;
res.setHeader('Location', pathname);
return res.end();
} else pathname = urlPath;
- // intentionally fall through
- case "ignore":
+ // intentionally fall through
+ case 'ignore':
{
if (isDirectory && !hasSlash) {
- pathname = urlPath + "/index.html";
- } else
- pathname = urlPath;
+ pathname = urlPath + '/index.html';
+ } else pathname = urlPath;
}
break;
- case "always":
+ case 'always':
if (!hasSlash) {
- pathname = urlPath + '/' +(urlQuery ? "?" + urlQuery : "");
+ pathname = urlPath + '/' + (urlQuery ? '?' + urlQuery : '');
res.statusCode = 301;
res.setHeader('Location', pathname);
return res.end();
- } else
- pathname = urlPath;
- break;
+ } else pathname = urlPath;
+ break;
}
// app.removeBase sometimes returns a path without a leading slash
pathname = prependForwardSlash(app.removeBase(pathname));
diff --git a/packages/integrations/node/test/trailing-slash.js b/packages/integrations/node/test/trailing-slash.js
index cdfef6d10..c46945b5a 100644
--- a/packages/integrations/node/test/trailing-slash.js
+++ b/packages/integrations/node/test/trailing-slash.js
@@ -8,7 +8,9 @@ import * as cheerio from 'cheerio';
*/
async function load() {
- const mod = await import(`./fixtures/trailing-slash/dist/server/entry.mjs?dropcache=${Date.now()}`);
+ const mod = await import(
+ `./fixtures/trailing-slash/dist/server/entry.mjs?dropcache=${Date.now()}`
+ );
return mod;
}
@@ -52,7 +54,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/some-base/one/');
@@ -60,7 +62,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/some-base/one/?foo=bar');
@@ -109,7 +111,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/one/');
@@ -117,7 +119,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/one/?foo=bar');
@@ -169,7 +171,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one/`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/some-base/one');
@@ -177,7 +179,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one/?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
@@ -227,7 +229,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one/`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
expect(res.headers.get('location')).to.equal('/one');
@@ -235,7 +237,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with redirect and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one/?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
expect(res.status).to.equal(301);
@@ -288,7 +290,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with slash', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one/`, {
- redirect : 'manual'
+ redirect: 'manual',
});
const html = await res.text();
const $ = cheerio.load(html);
@@ -299,7 +301,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route without slash', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one`, {
- redirect : 'manual'
+ redirect: 'manual',
});
const html = await res.text();
const $ = cheerio.load(html);
@@ -310,7 +312,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with slash and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one/?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
const html = await res.text();
const $ = cheerio.load(html);
@@ -321,7 +323,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route without slash and with query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/some-base/one?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
const html = await res.text();
const $ = cheerio.load(html);
@@ -382,7 +384,7 @@ describe('Trailing slash', () => {
it('Can render prerendered route with slash and query params', async () => {
const res = await fetch(`http://${server.host}:${server.port}/one/?foo=bar`, {
- redirect : 'manual'
+ redirect: 'manual',
});
const html = await res.text();
const $ = cheerio.load(html);
@@ -402,4 +404,3 @@ describe('Trailing slash', () => {
});
});
});
-