网络端口与服务预览
SeaCloud Sandbox 通过端口预览 URL 暴露服务。运行时 API 通常使用 9000 端口,你的应用应监听独立端口,例如 3000。
URL 模型
Section titled “URL 模型”https://{port}-{sandboxID}.{envdBaseDomain}/| URL | 含义 |
|---|---|
envdUrl,通常是 https://9000-{sandboxID}... | 运行时 API、健康检查、文件和进程。 |
https://3000-{sandboxID}... | 监听 3000 端口的应用。 |
启动简单静态预览
Section titled “启动简单静态预览”await sandbox.files.makeDir("/root/workspace/site");await sandbox.files.write( "/root/workspace/site/index.html", "<!doctype html><h1>Hello SeaCloud</h1>",);
await sandbox.commands.run("python3", { args: ["-m", "http.server", "3000", "--bind", "0.0.0.0", "--directory", "/root/workspace/site"], background: true,});
console.log(sandbox.getHost(3000));sandbox.files.make_dir("/root/workspace/site")sandbox.files.write( "/root/workspace/site/index.html", "<!doctype html><h1>Hello SeaCloud</h1>",)sandbox.commands.run( "python3", args=["-m", "http.server", "3000", "--bind", "0.0.0.0", "--directory", "/root/workspace/site"], background=True,)print(sandbox.get_host(3000))Vite 类开发服务
Section titled “Vite 类开发服务”await sandbox.commands.run("sh", { cwd: "/root/workspace", args: ["-lc", "npm run dev -- --host 0.0.0.0 --port 3000"], background: true,});
console.log(sandbox.getHost(3000));curl 推导 URL
Section titled “curl 推导 URL”使用原始 API 且已有 envdUrl 时,可以把运行时端口替换为应用端口。
APP_URL=$(printf '%s' "${ENVD_URL}" | sed 's#://9000-#://3000-#')echo "${APP_URL}"运行时健康检查与 Proxy
Section titled “运行时健康检查与 Proxy”用运行时健康检查区分 runtime 可达和应用就绪:
curl -i "${ENVD_URL}/health"托管运行时健康检查通常返回 204 No Content。GET {envdUrl}/ 可能返回类似 { "status": "ok" } 的轻量 JSON;这不代表你的应用运行在 9000 端口。
运行时也支持内部 proxy 形式:
GET {envdUrl}/proxy/3000/外部通配域名 URL 仍是推荐应用预览 URL:
https://3000-{sandboxID}.{envdBaseDomain}/| 现象 | 检查项 |
|---|---|
9000 返回健康检查,但应用不存在 | 9000 是运行时 API 端口,不是应用端口。 |
应用 URL 返回 502 | 进程退出、端口错误,或服务只绑定 127.0.0.1。 |
| 页面空白 | HTML 已返回,但静态资源缺失或 base path 错误。 |
| WebSocket 失败 | 确认框架使用同一主机和公网端口路由。 |
readyCmd 通过但预览失败 | 确认 readyCmd 检查的端口和用户打开的端口一致。 |