GoogleCloudPlatform / functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
Apache License 2.0
1.31k stars 160 forks source link

Advice on usage of `res.render()` from express. #652

Open mortenbekditlevsen opened 2 weeks ago

mortenbekditlevsen commented 2 weeks ago

Currently I get the following error in my functions logs occationally: Error: No default engine was specified and no extension was provided.

Reading about express, it appears that this is caused when calling render without a configured engine.

In logger.ts line 102, there is a call to res.render(...).

https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/acdfd93097331504d77658aa6159673f02f2d698/src/logger.ts#L102

Just dealing with Cloud Functions that can return a result or give an error, leaves me in doubt about where I should configure this engine, and to what, and for what purpose.

Could this error be communicated without the use of render? Or alternatively - could you provide guidance about when, where and why the configuration should happen?

danteoh commented 2 weeks ago

+1 to this - I'm literally just trying to run the vanilla cloud function sample code and running into this.

mortenbekditlevsen commented 2 weeks ago

Update: This appears to be happening on an internally defined 'express' app, so there's no way for us to configure the 'view engine', mening that this will always fail in a way that's hard for the end user to figure out.

My use case is that we have a customer that sends invalid json to an API. We would like to assist them with a concrete example of what goes wrong, but we can't intercept the request body before the error, and due to the res.render() call, all the user sees is an 'internal server error' even though the data is clearly bad.