Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing slash not removed in the route when '/' is defined in serverless.yml and prefix is specified in command line #1601

Closed
james-hu opened this issue Oct 25, 2022 · 4 comments · Fixed by #1606
Labels

Comments

@james-hu
Copy link

james-hu commented Oct 25, 2022

Bug Report

Current Behavior

Command line:

sls offline start --noPrependStageInUrl --prefix me --httpPort 3010

serverless.yml:

    events:
      - http:
          method: get
          path: '/'   # changing to '' does not make a difference, but '/{proxy+}' and '{proxy+}' seem to be effective workarounds

Output from serverless-offline:

GET | http://localhost:3010/me/                                         │
POST | http://localhost:3010/2015-03-31/functions/summary/invocations

Response when trying to access http://localhost:3010/me:

{"currentRoute":"get - /me","error":"Serverless-offline: route not found.","existingRoutes":["get - /me/"],"statusCode":404}

Expected behavior/code

Request to http://localhost:3010/me should not be rejected by serverless-offline with a 404 response. And this expectation is consistent with the behaviour of AWS.

Environment

  • serverless version: 3.23.0
  • serverless-offline version: 11.1.3
  • node.js version: 14.19.3
  • OS: macOS 12.6

Additional information*

In the old versions, serverless-offline is not that strict about trailing slash - if you can access http://localhost:3000/me then you can access http://localhost:3000/me/ and vice versa.

  • Behaviour in version 8: accessing both with and without trailing slash would be successful, and this is consistent with AWS
  • Behaviour in version 11: accessing with trailing slash would be successful, accessing without trailing slash would fail, and this is not consistent with AWS

Just saw this:

[11.1.0] (2022-10-09)
Features
  remove noStripTrailingSlashInUrl option ([71ee21d])
Maintenance Improvements
  remove stripTrailingSlash from hapi config ([22fd667])

I am curious, was it intentional to remove the support of accessing endpoint without trailing slash?

@james-hu
Copy link
Author

james-hu commented Oct 25, 2022

Could this change be a solution?
if (hapiPath !== '/' && hapiPath.endsWith('/') && hapiPath.endsWith('+}/')) { => if (hapiPath !== '/' && hapiPath.endsWith('/') && (path === '/' || path === '' || hapiPath.endsWith('+}/'))) {

PR created: #1602

@dnalborczyk
Copy link
Collaborator

dnalborczyk commented Oct 26, 2022

thank you for filing the issue @james-hu

I removed the noStripTrailingSlashInUrl flag as you noticed in v11.1.0, and added the expected functionality without setting the flag. as you mentioned, serverless-offline should behave the same as aws. that said, I might have missed your scenario, or didn't fully understand the use case for such a flag.

I'll try to look into this soon. labeling as a bug in the meantime.

@james-hu
Copy link
Author

Thank you @dnalborczyk !

@dnalborczyk
Copy link
Collaborator

@james-hu could you check if v11.2.2 fixes your problem (not sure if I got all permutations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants