You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Node.js至Google Cloud App Engine时遇404/500错误求助

部署Google Cloud App Engine时的Node.js应用前后端错误排查

我正尝试将带静态HTML前端的简易Node.js应用部署至Google Cloud App Engine,该应用本地运行正常,且此前曾成功部署后端API与前端。但在尝试同时部署两者及调试后,如今前端出现404错误、后端出现500错误。我已查看日志并耗时12小时排查,仍无头绪,怀疑问题出在app.yaml与package.json中。

当前app.yaml配置如下:

runtime: nodejs20
env: standard
instance_class: F1
handlers:
  - url: /api/quotes
    script: auto
  - url: /(.*)
    static_files: public/\1
    upload: public/.*
  - url: /(.*\.js)
    static_files: ../public/\1
    upload: /public/(.*\.js)
  - url: /(.*\.css)
    static_files: /public/\1
    upload: /public/(.*\.css)
  - url: /.*
    script: auto
  - url: .*
    script: auto
env_variables:
  MONGODB_URI: >-
    mongodb+srv://user:password@cluster0.effzkgn.mongodb.net/?retryWrites=true&w=majority
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: automatic
  min_pending_latency: automatic
  max_pending_latency: automatic
service_account: app-proj-name-here@appspot.gserviceaccount.com

日志textPayload字段显示:

from Error: Cannot find module '/workspace/server.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
    at Module._load (node:internal/modules/cjs/loader:901:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {

我知晓这是新手常见错误,恳请协助。


补充:
我已修复后端,/api/quotes路由可正常返回数据,但前端访问/路径仍出现404错误,推测问题仍在app.yaml配置中。

最新前端404日志显示:

logMessage: "Static file referenced by handler not found: public/"

浏览器错误提示:

Error: Not Found
The requested URL / was not found on this server.

我不清楚app.yaml中upload与static_files字段的具体用法,希望解决前端首页路径配置问题。

内容的提问来源于stack exchange,提问作者Evan R

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 11:31:01