Skip to content

Commit

Permalink
feat: remove noStripTrailingSlashInUrl option
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Oct 8, 2022
1 parent 7f8887c commit 71ee21d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 26 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions src/config/commandOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/config/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default {
localEnvironment: false,
noAuth: false,
noPrependStageInUrl: false,
noStripTrailingSlashInUrl: false,
noTimeout: false,
prefix: '',
reloadHandler: false,
Expand Down
11 changes: 3 additions & 8 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,16 @@ export default class HttpServer {
}

async createServer() {
const {
enforceSecureCookies,
host,
httpPort,
httpsProtocol,
noStripTrailingSlashInUrl,
} = this.#options
const { enforceSecureCookies, host, httpPort, httpsProtocol } =
this.#options

const serverOptions = {
host,
port: httpPort,
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
? {
Expand Down
6 changes: 1 addition & 5 deletions src/utils/generateHapiPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 3 additions & 4 deletions tests/endToEnd/trailingSlash/trailingSlash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 71ee21d

Please sign in to comment.