我正試圖在Google App Engine上部署我的網路應用。 我的專案遵循這樣的結構
app.yaml有以下內容:
runtime: nodejs14
處理程式:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: 1
upload: (.*)
但是,當我執行gcloud app deploy --project=MY PROJECT,并打開我的網站時,它看起來是這樣的:
我認為app.yaml檔案中存在一個錯誤,但我不明白是什么。有什么想法嗎?
uj5u.com熱心網友回復:
將你的第二個URL處理程式更新為:
- url: /(.*. (svg|png))$
static_files: www/images/1。
upload: www/images/.*.(svg|png)$
然后像這樣參考你的img src:
<img src="/test. png" alt="oops" width="104" height="142">
有一點需要補充,你也可以使用static_dir作為你的第二個URL處理程式。這種方式更容易組織每個目錄的靜態檔案。將你的app.yaml改為:
runtime: nodejs14。
處理程式:
- url: /
static_files: www/index.html
upload: www/index.html
- url:/span> /static-img
static_dir: www/images
在這個例子中,發生的情況是位于www/images的圖片被映射到以/static-img開始的URL上。你可以在你的HTML中使用該URL來參考你的img src。例如:
<img src="/static-img/test. png" alt="oops" width="104" height="142">
了解更多資訊請訪問。https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#handlers_static_dir
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/317606.html
標籤:
下一篇:智慧配電箱技術特點

