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

fix: return JSON in Node.js event template #211

Merged
merged 1 commit into from Nov 6, 2020

Conversation

lance
Copy link
Member

@lance lance commented Nov 5, 2020

The event template was just returning a string, but the default response
content type is application/json so browsers were failing to parse the string
as JSON.

Signed-off-by: Lance Ball lball@redhat.com

@lance lance added the templates/node Related to the Node.js function templates label Nov 5, 2020
@lance lance requested a review from a team November 5, 2020 19:45
@lance lance self-assigned this Nov 5, 2020
*/
function verifyUser(context, user) {
if (!context.cloudevent) {
return 'No cloud event received';
return {
message: 'No cloud event received'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, what if it returned:

return '"No cloud event received"'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would probably parse correctly by the browser.

The event template was just returning a string, but the default response
content type is application/json so browsers were failing to parse the string
as JSON.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance merged commit beb838f into knative:main Nov 6, 2020
@lance lance deleted the nodejs-return-json branch November 6, 2020 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
templates/node Related to the Node.js function templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants