GCF Cannot set property path of #<IncomingMessage>
Closed this issue ยท 2 comments
sanderhahn commented
Deploying a minimal polka hello world in Google Cloud Functions will result in the following error. One workaround is to add a path
setter to the req object (see example), but this feels a bit hacky :)
TypeError: Cannot set property path of #<IncomingMessage> which has only a getter
at Polka.handler (/srv/functions/node_modules/polka/index.js:74:29)
at process.nextTick (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:243:17)
at process._tickCallback (internal/process/next_tick.js:61:11)
Example code with path setter:
// deploy using:
// gcloud functions deploy polka --runtime nodejs10 --trigger-http
const polka = require('polka');
const app = polka()
.get('/', (req, res) => {
res.end(`Hello world`);
});
if (require.main === module) {
app.listen(3000, err => {
if (err) throw err;
console.log(`> Running on http://localhost:3000`);
});
}
exports.polka = (req, res) => {
// define a path property setter on req
var path = req.path;
Object.defineProperty(req, 'path', {
get: function () {
return path;
},
set: function (newValue) {
path = newValue;
},
});
app.handler(req, res);
}
lukeed commented
Hi, thank you!
This is actually a duplicate of #86
There will be a GCF "adapter" come 1.0 that applies a workaround for (and only for) GCF applications. It's not worth including that change globally, for a few reasons.
Also, FYI, GCF is using Express under the hood already, so you gain no benefit in using Polka there ๐
Thank you for the detailed report though ๐
sanderhahn commented
Sorry missed that issue... thanks for the quick response :)