Serverless-offline: Stage name in the URL not set

Created on 18 Dec 2019  Â·  9Comments  Â·  Source: dherault/serverless-offline

Imagine we have a path defined in serverless.yml as GET example.
So by running sls offline -s dev command, serverless-offline will create the route GET /example. But API Gateway also prepends the stage name to the path. So, API Gateway would have created GET /dev/example route.
How to achieve that using serverless-offline?

bug enhancement

Most helpful comment

@dnalborczyk Thanks. That was fast! I will definitely try it.

All 9 comments

hey @pSnehanshu thank you for opening this issue!

this is something I thought about adding. in the meanwhile you _might_ be able to facilitate serverless variables (although I haven't tried it myself):

functions:
  hello:
    handler: handler.hello
    path: ${opt:stage, 'dev'}/hello

@dnalborczyk thanks, but that won't be interoperable with API Gateway.


Sincerely,
Snehanshu Phukon

(Sent from mobile phone)

On Wed, 18 Dec, 2019, 7:33 PM dnalborczyk, notifications@github.com wrote:

hey @pSnehanshu https://github.com/pSnehanshu thank you for opening
this issue!

this is something I thought about adding. in the meanwhile you might be
able to facilitate serverless variables
https://serverless.com/framework/docs/providers/aws/guide/variables/
(although I haven't tried it myself):

functions:
hello:
handler: handler.hello
path: ${opt:stage, 'dev'}/hello

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dherault/serverless-offline/issues/857?email_source=notifications&email_token=ACHVBXWRHM7JGG5XZJAPQ73QZIUURA5CNFSM4J4IWXY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHGGULY#issuecomment-567044655,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACHVBXR2CB2TPUFJ3R4WDPTQZIUURANCNFSM4J4IWXYQ
.

@pSnehanshu you can give it a try with v6.0.0-alpha.55 . it supports cli stage, yml provider stage and default (dev). feedback is welcome!

@dnalborczyk Thanks. That was fast! I will definitely try it.

Hum... this seems to be a pretty big breaking change: from one alpha release to another, nothings work anymore, due to this stage prepending.

I got this error:

Error: Path cannot end with a trailing slash when configured to strip: OPTIONS /dev/

I understand it can be useful, but I think it needs to be conditioned by an option flag.

hey @leny thank you for testing the alpha version!

Hum... this seems to be a pretty big breaking change: from one alpha release to another, nothings work anymore, due to this stage prepending.

that's why we are still releasing alpha tags, to allow for breaking changes, since we try to follow semver. breaking changes should be in the release log. there shouldn't be much more breaking changes coming, other than fixing _everything_ CORS related. beta version should be released hopefully fairly soon with a full version beginning of next year.

I got this error:

Error: Path cannot end with a trailing slash when configured to strip: OPTIONS /dev/

do you have some repro steps to get to your issue? it looks it is CORS related.

The only repro I have is to upgrade from alpha-54 to alpha-55.

The function which cause issue seems to be this one (I let the second function here seems they are related):

functions:
  endpointCORSHandler:
    handler: bin/handlers/endpoint-cors.handler
    package:
      individually: true
      artifact: bin/handlers/endpoint-cors.zip
    events:
      - http:
          path: /
          method: options
  endpoint:
    handler: bin/handlers/endpoint.handler
    package:
      individually: true
      artifact: bin/handlers/endpoint.zip
    memorySize: 512
    events:
      - http:
          path: /
          method: any
          cors: true

The code for the function isn't really relevant, it's just sending some CORS-headers to the client as answer to the OPTIONS request.

I have the error directly when running npx sls offline.

thank you @leny !

the issue seems to be: path: /. I'll have a look.

@leny should be hopefully fixed with: v6.0.0-alpha.56. thanks again for testing the alpha version!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adambiggs picture adambiggs  Â·  4Comments

Rafaelsk picture Rafaelsk  Â·  4Comments

jormaechea picture jormaechea  Â·  4Comments

conradoramalho picture conradoramalho  Â·  3Comments

JimLynchCodes picture JimLynchCodes  Â·  4Comments