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

部署至Google Cloud App后term.js的Ajax请求返回404,本地正常求助

Troubleshooting Term.js Ajax 404 on Google Cloud Deployed Java REPL

Hey there! Since your Java REPL works perfectly locally but throws 404s on term.js Ajax requests after deploying to Google Cloud, let's walk through the most likely configuration gaps you might have missed:

1. App Engine Routing Configuration (app.yaml)

Google Cloud App Engine relies on app.yaml to route incoming requests to your Java backend. If your term.js is hitting a specific endpoint (like /session or /repl/api/*), you need to make sure the handlers section in app.yaml explicitly maps those paths to your application.

For example, if your API endpoints start with /repl/, your app.yaml should include:

handlers:
  - url: /repl/.*
    script: auto
    secure: always  # Ensures all requests use HTTPS

Double-check that the url pattern matches exactly what term.js is requesting—even a small prefix mismatch can cause a 404.

2. Hardcoded HTTP URLs in Term.js

Local development often uses http://localhost:8080/... for requests, but when deployed to HTTPS on Google Cloud, these hardcoded HTTP URLs will either be blocked by browser mixed-content policies or point to the wrong location.

Open up your term.js file and look for any absolute request URLs. Replace them with relative paths (e.g., change http://localhost:8080/api/session to /api/session). This way, the request will automatically use the current domain's HTTPS protocol and host.

3. Backend Context Path Mismatch

If you're using a framework like Spring Boot, check your application's context path configuration. Locally, you might have server.servlet.context-path set to an empty string, but if you deployed a WAR file or adjusted this setting for GCP, it could add an unexpected prefix to your API endpoints.

For example, if your context path is set to /java-repl, your API endpoint would be /java-repl/session instead of /session—make sure term.js is using the correct full path.

4. Static Resource vs API Route Priority

If your app.yaml has a handler for static resources (like your frontend JS/CSS) that matches a broad pattern (e.g., /.*) before your API handler, App Engine might try to serve your API request as a static file, leading to a 404.

Reorder your handlers so API routes come first, or narrow the static resource pattern:

handlers:
  # API routes first
  - url: /api/.*
    script: auto
    secure: always
  # Static resources second
  - url: /static/.*
    static_dir: static

5. CORS Configuration (If Applicable)

While this is less likely if your frontend and backend are on the same domain, local development doesn't enforce CORS strictly like production environments do. If term.js is making requests across subdomains or if you're embedding the REPL in another site, your Java backend needs proper CORS headers.

For Spring Boot, add the @CrossOrigin annotation to your API controllers, or configure a global CORS filter. For traditional servlets, add a CORS filter to your web.xml.

Quick Debug Tip

First, open your browser's developer tools (F12) and check the Network tab. Look at the exact URL that's returning 404—this will tell you immediately if the path is wrong, the protocol is mismatched, or the request is going to the wrong place.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:04:45