'How to deploy nodejs + angular app to Google Cloud Platform
I have a nodejs backend and an angular frontend app in the same folder. The angular app outputs the build files to a static folder and nodejs uses the following to load the html file
//Idiomatic expression in express to route and respond to a client request
app.get('/', (req, res) => { //get requests to the root ("/") will route here
res.sendFile(process.cwd()+"/angularApp/static/index.html") //server responds by sending the index.html file to the client's browser
//the .sendFile method needs the absolute path to the file, see: https://expressjs.com/en/4x/api.html#res.sendFile
});
This is my app.yaml for nodejs :
runtime: nodejs16
handlers:
- url: /
static_files: angularApp/static/index.html
upload: angularApp/static/index.html
- url: /
static_dir: angularApp/static
However when I deploy the app to GCP I get the following errors in the console
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
What should the app.yaml file contain?
Solution 1:[1]
Tou can take a look of how docker works. Basically, you put your dependencies and source code into an image, then you ca easily deploy it on google cloud platform https://cloud.google.com/run/docs/deploying .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Valentin |
