I have a Dockerfile with a service that I can successfully run locally and when I deploy it to Google Cloud with Cloud Run everything seems to work as well as there are no errors, but when I make a request to a url that should exist I get back 404.
This is my Dockerfile
FROM node:16-alpine3.14
WORKDIR /usr/src/app
COPY . ./
RUN npm install
RUN npm run build
RUN npm ci --only=production
CMD node ./dist/index.js
The 2 commands I use to deploy my service are
gcloud builds submit --tag gcr.io/{project-id}/backend-version-1.0.0 .
gcloud run deploy test-gcp-deploy --image gcr.io/{project-id}/backend-version-1.0.0 --region europe-west3 --platform managed --allow-unauthenticated --quiet --max-instances 2
My Typescript code contains this part
const port = process.env.PORT || 800;
...
app.get( "/healthz", ( req, res ) => {
res.send( { status: 'running'} );
} );
app.listen( port, () => {
console.log( `server started at http://localhost:${ port }` );
} );
My Cloud run service logs contain the following lines after one unsuccessful navigation to the url of the service that is auto generated.
2022-02-01T22:07:18.800340Z server started at http://localhost:8080
2022-02-01T22:07:25.301169Z Cloud Run test-gcp-deploy {@type: type.googleapis.com/google.cloud.audit.AuditLog, resourceName: namespaces/{project-id}/services/test-gcp-deploy, response: {…}, serviceName: run.googleapis.com, status: {…}}
2022-02-01T22:07:48.659515Z GET 404 945 B 12ms Chrome 97 https://{service-url}
I added the logs in addition to the code as a proof that the environment variable PORT reaches my service as the port is 8080 instead of the default 800.
I have tried the urls
https://{service-url} => resolves to => Cannot GET /
https://{service-url}/healthz => resolves to => 404. That’s an error.The requested URL /healthz was not found on this server.
https://{service-url}:8080 => resolves to => This site can’t be reached
https://{service-url}:8080/healthz => resolves to => This site can’t be reached
Can anybody point out what I am doing wrong? I am happy to provide any additional information if that would help you answer my question.