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);
}
Deploying a minimal polka hello world in Google Cloud Functions will result in the following error. One workaround is to add a
pathsetter to the req object (see example), but this feels a bit hacky :)Example code with path setter: