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
Problem with parsing JSON requestTemplate since it is already js object #3
Comments
You're right, 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 Thanks for the issue! |
Yeah. I noticed that after fiddling for a while. Then I found another error in second route and ended up catching whole error:
This way it at least doesn't crash all the time. |
I wanted to get rid of the JSON parsing, but do you think it is still necessary ? |
Just get rid of it. It was nice to have something automatic for simple cases. |
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 ? |
I replaced |
Publised under v0.2.2 |
…t-rebased Explained integration types in the docs
I had problem with parsing my request templates. I made this little fix to test if template is already js object:
In index.js:163
The text was updated successfully, but these errors were encountered: