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

stringified JSON is parsed offline, stringified online #702

Closed
frsechet opened this issue Jun 9, 2019 · 1 comment
Closed

stringified JSON is parsed offline, stringified online #702

frsechet opened this issue Jun 9, 2019 · 1 comment

Comments

@frsechet
Copy link
Contributor

frsechet commented Jun 9, 2019

It appears serverless-offline is parsing a stringified JSON response of a lambda integration, hence giving a different result online vs. offline.

Considering the following function:

module.exports.hello = async (event) => {
  return JSON.stringify({ toto: "tutu" });
};

And the following serverless.yml:

service: testjson

plugins:
  - serverless-offline

provider:
  name: aws
  runtime: nodejs10.x
  stage: dev
  region: eu-west-3

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: test
          method: GET
          integration: lambda
          cors: true

When running locally, I get:

$ curl http://localhost:3000/test
{"toto":"tutu"}

When deployed, I get:

$ curl https://whatever.execute-api.eu-west-3.amazonaws.com/dev/test
"{\"toto\":\"tutu\"}"

However, if I change the function to:

module.exports.hello = async (event) => {
  return { toto: "tutu" };
};

I get {"toto":"tutu"} everywhere (as expected).

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

No branches or pull requests

4 participants