简体   繁体   English

如何部署nodejs + angular app到谷歌云平台

[英]How to deploy nodejs + angular app to Google Cloud Platform

I have a nodejs backend and an angular frontend app in the same folder.我在同一个文件夹中有一个 nodejs 后端和一个 angular 前端应用程序。 The angular app outputs the build files to a static folder and nodejs uses the following to load the html file angular 应用程序将构建文件输出到 static 文件夹,nodejs 使用以下内容加载 html 文件


//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:这是我的 app.yaml 的 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但是,当我将应用程序部署到 GCP 时,我在控制台中收到以下错误

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html".加载模块脚本失败:应为 JavaScript 模块脚本,但服务器响应 MIME 类型为“text/html”。 Strict MIME type checking is enforced for module scripts per HTML spec.根据 HTML 规范,对模块脚本强制执行严格的 MIME 类型检查。

What should the app.yaml file contain? app.yaml 文件应该包含什么?

Tou can take a look of how docker works. Tou 可以看看 docker 是如何工作的。 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 .基本上,您将依赖项和源代码放入图像中,然后可以轻松地将其部署到谷歌云平台https://cloud.google.com/run/docs/deploying 上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM