Comments (7)
You're right, requestTemplates
as defined per const requestTemplates = endpoint.requestTemplates;
is already an Object, so there is no need for parsing. I've been working on 1.0 (that should supports velocity in full) on master but I'll create a branch for it.
Allow 30 min, I'll publish a new version applying your fix. Make sure you've read the source (you've done it obviously) before using the --useTemplates
option, it's very opinionated.
Thanks for the issue!
from serverless-offline.
Yeah. I noticed that after fiddling for a while. Then I found another error in second route and ended up catching whole error:
try {
toApply = JSON.parse(jsonContent);
} catch (e) {
toApply = {};
}
This way it at least doesn't crash all the time.
from serverless-offline.
I wanted to get rid of the JSON parsing, but do you think it is still necessary ?
from serverless-offline.
Just get rid of it. It was nice to have something automatic for simple cases.
from serverless-offline.
This is a fix, not amazing:
// Then we create the event object
const event = Object.assign({ isServerlessOffline: true }, request);
if (requestTemplates && this.evt.useTemplates) {
// Apply request template to event
const requestTemplate = requestTemplate[request.mime || 'application/json'];
if (typeof requestTemplate === 'object') {
try {
// TODO: proces $context variables in a more complete way http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference
// TODO: $input could also be dealt with in a more robust way http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference
for (let key in requestTemplate) {
if (requestTemplate[key] === '$context.httpMethod') {
event[key] = request.method.toUpperCase();
} else if (requestTemplate[key] === '$input.params()') {
event[key] = request.params;
} else {
const reResp = reInputParam.exec(requestTemplate[key]);
if (reResp) {
// lookup variable replacement in params
const paramName = reResp[1];
event[key] = paramName in event.params ? event.params[paramName] : '';
}
else {
event[key] = requestTemplate[key];
}
}
}
}
catch (err) {
SCli.log('Error while trying to use your templates:');
console.log(err.stack || err);
serverResponse.statusCode = 500;
serverResponse.source = 'Error while trying to use your templates.';
serverResponse.send();
return;
}
}
}
What do you think ?
from serverless-offline.
I replaced if (typeof requestTemplate === 'object') {
with if (requestTemplate) {
from serverless-offline.
Publised under v0.2.2
from serverless-offline.
Related Issues (20)
- Scheduled Lambda timeout error 504 after execution HOT 11
- Support for Python 3.10 (and 3.11) HOT 5
- Add Ruby 3.2 runtime support HOT 3
- Unhandled exception in handler 'index'. HOT 1
- Bump serverless-offline version to 12.0.5 HOT 1
- How to run lambda integration mode in serverless locally
- App hangs when launching in debug mode on Webstorm HOT 2
- ALB event doesn't reflect custom headers specified in handler.ts HOT 2
- dotnet6 future donet7 support HOT 1
- clientCert property is undefined when client certificates are used
- Extend support for ALB event paths
- Enable mixed API usage with same routes
- SLS_ACCOUNT_ID identity override for schedule events
- I think you removed Node 16 support too soon HOT 1
- 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
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.