[英]How to deploy nodejs + angular app to Google Cloud Platform
我在同一个文件夹中有一个 nodejs 后端和一个 angular 前端应用程序。 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
});
这是我的 app.yaml 的 nodejs:
runtime: nodejs16
handlers:
- url: /
static_files: angularApp/static/index.html
upload: angularApp/static/index.html
- url: /
static_dir: angularApp/static
但是,当我将应用程序部署到 GCP 时,我在控制台中收到以下错误
加载模块脚本失败:应为 JavaScript 模块脚本,但服务器响应 MIME 类型为“text/html”。 根据 HTML 规范,对模块脚本强制执行严格的 MIME 类型检查。
app.yaml 文件应该包含什么?
Tou 可以看看 docker 是如何工作的。 基本上,您将依赖项和源代码放入图像中,然后可以轻松地将其部署到谷歌云平台https://cloud.google.com/run/docs/deploying 上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.