I am uploading my nodejs source code via Cloud Build which uses gcloud function command. This function has failed to deploy and will not work correctly. The error I get is:
Function 'myFunction' is not defined in the provided module.
Did you specify the correct target function to execute?
Could not load the function, shutting down.. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
My gcloud command:
gcloud functions deploy my-cgp-function
--set-env-vars "SERVE_MODE=GCP-FUNCTION"
--project=my-project-xxx
--region=europe-west2
--runtime=nodejs18
--entry-point=myFunction
--trigger-http
--allow-unauthenticated
Here is my nodejs code:
const buildFastify = require('./app');
global.nodeRoot = require("path").resolve(__dirname) + "/";
buildFastify().then(async (fastify) => {
if (process.env.SERVE_MODE === 'GCP-FUNCTION') {
module.exports = {
myFunction: async (request, reply) => {
await fastify.ready();
fastify.server.emit('request', request, reply);
}
}
} else {
fastify.listen(8011, "0.0.0.0", (err, address) => {
if (err) throw err;
fastify.log.info(`server listening on ${address}`);
});
}
}).catch(console.error)
It seems that maybe some of the Fastify middleware modifies the request.
I tried to run this locally with the GCP Functions framework but I got the same.
I am not sure how to get around this issue.