Comments (15)
@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.
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.
@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.
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.
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.
thanks...
from serverless-offline.
I don't see the response content-type set as text, in which case do you have this ?
from serverless-offline.
Anyway, I worked a fix, v1.2.6, please review it, thanks.
from serverless-offline.
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.
With v1.2.6 ?
from serverless-offline.
just pulled latest version and it works ... thanks ;)
from serverless-offline.
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.
@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.
@spardo @martinmicunda Done. run npm update
to download the new v1.3.0
.
See the new docs for usage. Happy coding!
from serverless-offline.
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)
- How to set timeout properly HOT 1
- Add support for nodejs20.x runtime
- Stripping trailing slashes breaks django admin
- Inconsistency in `authorizer` Model When Using `serverless-offline` with AWS PowerTools for Lambda HOT 2
- How to clear cache on cognito HOT 1
- x-api-key no longer being provided HOT 4
- Lambci docker images are deprecated and no more maintained. HOT 1
- contentHandling
- MaxListenersExceededWarning with esbuild
- Expired image for lambci/lambda:go1.x HOT 3
- Sponsors inquiry
- Node 20 support? HOT 3
- serverless offline with angular cli application
- NODE_PRESERVE_SYMLINKS option?
- free(): invalid next size (fast), Segmentation Faults (SIGSEGV) and other native Node.js crashes HOT 4
- Purpose of env.AUTHORIZER
- Disable lambda print to console
- Clarity on `identitySource` and `authorization` header in authorizers
- Support lambda direct requests over HTTPS
- Profile X requires multi-factor authentication, but no MFA code callback was provided
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-offline.