From 71ee21db253f601f5355377e1a67d641fc447bea Mon Sep 17 00:00:00 2001 From: dnalborczyk Date: Fri, 7 Oct 2022 22:52:19 -0400 Subject: [PATCH] feat: remove noStripTrailingSlashInUrl option --- README.md | 4 ---- src/config/commandOptions.js | 4 ---- src/config/defaultOptions.js | 1 - src/events/http/HttpServer.js | 11 +++-------- src/utils/generateHapiPath.js | 6 +----- tests/endToEnd/trailingSlash/trailingSlash.test.js | 7 +++---- 6 files changed, 7 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4189d01c5..3b344127e 100644 --- a/README.md +++ b/README.md @@ -195,10 +195,6 @@ Turns off all authorizers. Don't prepend http routes with the stage. -#### noStripTrailingSlashInUrl - -Don't strip trailing slash from http routes. - #### noTimeout -t Disables the timeout feature. diff --git a/src/config/commandOptions.js b/src/config/commandOptions.js index 9a4e785e6..fc179a734 100644 --- a/src/config/commandOptions.js +++ b/src/config/commandOptions.js @@ -85,10 +85,6 @@ export default { type: 'boolean', usage: "Don't prepend http routes with the stage.", }, - noStripTrailingSlashInUrl: { - type: 'boolean', - usage: "Don't strip trailing slash from http routes.", - }, noTimeout: { shortcut: 't', type: 'boolean', diff --git a/src/config/defaultOptions.js b/src/config/defaultOptions.js index fc06d276a..7b7f164ed 100644 --- a/src/config/defaultOptions.js +++ b/src/config/defaultOptions.js @@ -17,7 +17,6 @@ export default { localEnvironment: false, noAuth: false, noPrependStageInUrl: false, - noStripTrailingSlashInUrl: false, noTimeout: false, prefix: '', reloadHandler: false, diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js index 043b0acd0..6f73848cd 100644 --- a/src/events/http/HttpServer.js +++ b/src/events/http/HttpServer.js @@ -68,13 +68,8 @@ export default class HttpServer { } async createServer() { - const { - enforceSecureCookies, - host, - httpPort, - httpsProtocol, - noStripTrailingSlashInUrl, - } = this.#options + const { enforceSecureCookies, host, httpPort, httpsProtocol } = + this.#options const serverOptions = { host, @@ -82,7 +77,7 @@ export default class HttpServer { router: { // allows for paths with trailing slashes to be the same as without // e.g. : /my-path is the same as /my-path/ - stripTrailingSlash: !noStripTrailingSlashInUrl, + stripTrailingSlash: false, }, state: enforceSecureCookies ? { diff --git a/src/utils/generateHapiPath.js b/src/utils/generateHapiPath.js index 2b48b6fdf..7f56b02a7 100644 --- a/src/utils/generateHapiPath.js +++ b/src/utils/generateHapiPath.js @@ -12,11 +12,7 @@ export default function generateHapiPath(path, options, serverless) { hapiPath = `/${options.prefix}${hapiPath}` } - if ( - hapiPath !== '/' && - hapiPath.endsWith('/') && - (!options.noStripTrailingSlashInUrl || hapiPath.endsWith('+}/')) - ) { + if (hapiPath !== '/' && hapiPath.endsWith('/') && hapiPath.endsWith('+}/')) { hapiPath = hapiPath.slice(0, -1) } diff --git a/tests/endToEnd/trailingSlash/trailingSlash.test.js b/tests/endToEnd/trailingSlash/trailingSlash.test.js index 44c5ea8a9..97c53aa38 100644 --- a/tests/endToEnd/trailingSlash/trailingSlash.test.js +++ b/tests/endToEnd/trailingSlash/trailingSlash.test.js @@ -6,17 +6,16 @@ import { setup, teardown } from '../../_testHelpers/index.js' const __dirname = dirname(fileURLToPath(import.meta.url)) -describe('noStripTrailingSlashInUrl option', function desc() { +describe("don't strip trailing slash in url option", function desc() { beforeEach(() => setup({ - args: ['--noStripTrailingSlashInUrl'], servicePath: resolve(__dirname, 'src'), }), ) afterEach(() => teardown()) - describe('when --noStripTrailingSlashInUrl is used, and request is made ending with slash', () => { + describe('request is made ending with slash', () => { it('it should not be removed', async () => { const url = new URL('/dev/echo/something/', BASE_URL) const response = await fetch(url) @@ -29,7 +28,7 @@ describe('noStripTrailingSlashInUrl option', function desc() { }) }) - describe('when --noStripTrailingSlashInUrl is used, events with and without slash can co-exist', () => { + describe('events with and without slash can co-exist', () => { it('it should not be removed', async () => { let url = new URL('/dev/echo/test', BASE_URL) let response = await fetch(url)