[英]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.