Giter Site home page Giter Site logo

Comments (15)

dherault avatar dherault commented on May 27, 2024 1

@spardo spardo Using (request and response) parameters is hard because it really has to do with integrations, but I'll try something.

@martinmicunda You can teak you template to make it work with Offline:

   "404": {
      "statusCode": "404",
      "selectionPattern": ".*\"statusCode\":404.*",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
        "application/json": "#set($inputRoot = $input.path('$.errorMessage'))\n$inputRoot"
      }
   }

But I'll commit something to make it work with your code soon.

from serverless-offline.

martinmicunda avatar martinmicunda commented on May 27, 2024

I am currently working on error API Gateway and lambda error handling and here is my use case:

"responses": {
   "default": {
      "statusCode": "200",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
          "application/json": ""
      }
   },
   ".*\"statusCode\":404.*": {
      "statusCode": "404",
      "responseParameters": {},
      "responseModels": {},
      "responseTemplates": {
        "application/json": "#set($inputRoot = $input.path('$.errorMessage'))\n$inputRoot"
      }
   }
}

handler.js

context.fail(JSON.stringify({"statusCode":404,"error":"Not Found"}));

The above example works on AWS. Not sure if this on your roadmap but it would be nice if offline plugin could match regular expression and return 404 statusCode with errorMessage (currently is returning 200). This is nice article about API Gateway error handling.

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

@martinmicunda Solved in v1.2.2.

@spardo It seems like a long road, but request and response parameters are on their way 😅
EDIT: I'll finally wait for Serverless 0.5 before I work on that.

from serverless-offline.

martinmicunda avatar martinmicunda commented on May 27, 2024

I am starting to have same request like @spardo :) I try to set up response content-type to json (offline currently return conte-type as text) so it would be nice to have this feature in the offline plugin :)

  "responseParameters": {
    "method.response.header.Content-Type": "'application/json; charset=UTF-8'"
  }

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

Content-type returned as text is a bug! I'll fix it!
I've been thinking about request/responseParameters, it's possible, but will take some time.

from serverless-offline.

martinmicunda avatar martinmicunda commented on May 27, 2024

thanks...

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

I don't see the response content-type set as text, in which case do you have this ?

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

Anyway, I worked a fix, v1.2.6, please review it, thanks.

from serverless-offline.

martinmicunda avatar martinmicunda commented on May 27, 2024

sorry .. The content-type doesn't seem to be set at all... I am using Postman for testing and I have test for response content-type. Shouldn't the offline plugin send content-type="application/json; charset=UTF-8" or at least to be able somehow to configure respond..

cache-control:no-cache
Connection:keep-alive
content-length:139
Date:Tue, 15 Mar 2016 15:42:17 GMT
vary:origin,accept-encoding

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

With v1.2.6 ?

from serverless-offline.

martinmicunda avatar martinmicunda commented on May 27, 2024

just pulled latest version and it works ... thanks ;)

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

Sweet! I'll start working on request/responseParameters right away. Won't be before friday I think.

EDIT: @spardo @martinmicunda Only responseParameters for starters, because for requestParameters I need to hijack Hapijs's request, I'll do that later.

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

@spardo @martinmicunda So it seems that only header modification is supported by APIG's responseParameters when it comes to lambda integrations.

1.3.0 is on it's way, will support
"method.response.header.xxx": "integration.response.body"
"method.response.header.xxx": "integration.response.body.__JSONpath__"
"method.response.header.xxx": "integration.response.header.yyy"
"method.response.header.xxx": "__customHeader__"

Also, the current doc is ugly and confusing so I'll work on that.

from serverless-offline.

dherault avatar dherault commented on May 27, 2024

@spardo @martinmicunda Done. run npm update to download the new v1.3.0.
See the new docs for usage. Happy coding!

from serverless-offline.

spardo avatar spardo commented on May 27, 2024

Thank you very much and sorry for going dark, I was not receiving any email notifications. Can't wait to test it out.

from serverless-offline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.