Web Hosting
最后更新:2026年6月22日
Web Hosting 是将构建好的静态网站上传到 Space,并以 {subdomain}.weegloo.app 地址提供服务的资源。以服装商城为例,将构建好的商城站点发布到 dailywear-shop.weegloo.app,就是一个 Web Hosting。
上传顺序如下。首先将构建结果打包为 ZIP 或 tar.gz,通过 Upload API 上传以获得一个 Upload。然后引用该 Upload,使用 POST /web-hostings 创建 Web Hosting。当系统处理完上传的文件、sys.state 变为 COMPLETED 后,即可通过 url 访问站点。在 CMA 中,Web Hosting 是 Space 的子资源,路径以 /spaces/{spaceId}/web-hostings 为基准。
资源结构
下面是处理完成的 Web Hosting「DailyWear 商城网站」的单条查询响应。它包含 sys(系统属性)以及主体属性(name、description、isSpa、subdomain、url)。
{
"sys": {
"id": "3trmXRM3RqbgSnifyg7PWeb01Examp",
"type": "WebHosting",
"space": { "sys": { "id": "HnQ32YiH", "type": "Refer", "targetType": "Space" } },
"createdBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"updatedBy": { "sys": { "id": "3p4tcFbQRwz503VXdtHXNI5dZH5TVB", "type": "Refer", "targetType": "User" } },
"createdAt": "2026-06-18T11:40:00.000Z",
"updatedAt": "2026-06-18T11:40:05.000Z",
"state": "COMPLETED",
"totalFileSize": 245786,
"version": 3
},
"name": "DailyWear 商城网站",
"description": "服装、杂货商城静态站点",
"isSpa": true,
"subdomain": "dailywear-shop",
"url": "https://dailywear-shop.weegloo.app"
}主要键:
subdomain:站点提供服务所用的子域名。上例为dailywear-shop,最终地址为dailywear-shop.weegloo.app。url:处理完成后可访问的站点地址。isSpa:是否为单页应用(SPA)。为true时,所有路径请求都会被发送到index.html。state:上传文件的部署处理状态。在下方系统属性 (sys)中说明。
系统属性 (sys)
每个 Web Hosting 都将通用的系统属性存放在 sys 对象中。space、createdBy、updatedBy 采用 Refer 形式({ "sys": { "id", "type": "Refer", "targetType" } })。
| 属性 | 类型 | 说明 |
|---|---|---|
id | string | 资源唯一标识符。用于单条查询、修改、删除路径中的 {webHostingId}。 |
type | string | 资源种类。Web Hosting 始终为 "WebHosting"。 |
space | Refer<Space> | 该 Web Hosting 所属的 Space。 |
createdBy | Refer<User> | 创建该资源的用户。 |
createdAt | string (date-time) | 创建时间。 |
updatedBy | Refer<User> | 最后修改的用户。 |
updatedAt | string (date-time) | 最后修改时间。 |
state | string (enum) | 部署处理状态。为下列 4 种之一。 |
error | string | 处理失败时的原因。未失败时为空。 |
totalFileSize | integer | 上传文件的总大小(字节)。 |
version | integer (≥1) | 资源版本。每次创建、修改都会加 1。修改、部分修改请求需要通过 x-weegloo-version 携带该值。 |
state 表示部署上传文件的处理阶段。它不是 Content 的发布状态,Web Hosting 也没有发布或归档的概念。文件处理完成、变为 COMPLETED 后,即可通过 url 访问站点。
state | 含义 |
|---|---|
PENDING | 等待处理。 |
PROCESSING | 处理中。 |
COMPLETED | 处理完成。可通过 url 访问。 |
FAILED | 处理失败。原因存放在 sys.error 中。 |
主体属性
Web Hosting 的主体属性如下。
| 属性 | 类型 | 说明 |
|---|---|---|
name | string (1~64) | Web Hosting 名称。创建时必填。 |
description | string (≤128) | 说明。可选。 |
isSpa | boolean | 是否为单页应用。为 true 时所有路径请求都会被发送到 index.html(用于 SPA 路由)。创建时必填。 |
subdomain | string (3~32) | 服务子域名。模式为 ^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$(小写字母、数字、连字符,首尾不可为连字符)。创建时必填。 |
upload | Refer<Upload> | 指向待上传文件的引用。为 ZIP 或 tar.gz,根目录需有 index.html,资源需以相对路径引用。 |
url | string | 处理完成后的访问 URL。由系统填充。 |
fromPath | string | 部署基准路径。 |
customDomain | string | 已连接的自定义域名。可选。在下方自定义域名中说明。 |
子域名检查
在创建 Web Hosting 之前,可以检查想要使用的子域名是否空闲。向 GET /web-hostings/availability?subdomain=... 通过 subdomain 查询参数传入要检查的子域名即可。
响应为以下形式,available 为 true 时即可使用该子域名。
{ "subdomain": "dailywear-shop", "available": true }自定义域名
可以将自己拥有的域名连接到 Web Hosting,代替默认地址 {subdomain}.weegloo.app。已连接域名的状态以 customDomain 对象表示,形式为 { id, domain, dns, cert }。dns 和 cert 分别为域名所有权验证(DNS)和证书签发(cert)状态,二者均为 { status, txtName, txtContent } 形式。txtName、txtContent 是需要在域名端注册的 DNS TXT 记录的名称和值。
{
"id": 1024,
"domain": "shop.dailywear.example",
"dns": {
"status": "PENDING",
"txtName": "_weegloo.shop.dailywear.example",
"txtContent": "weegloo-verify=3trmXRM3RqbgSnifyg7PWebVerifyEx"
},
"cert": {
"status": "PENDING",
"txtName": "_acme-challenge.shop.dailywear.example",
"txtContent": "acme-verify=3trmXRM3RqbgSnifyg7PWebCertEx"
}
}在域名端注册 TXT 记录后,使用 PUT /web-hostings/{webHostingId}/custom-domain/status/verify 触发验证,并通过 GET /web-hostings/{webHostingId}/custom-domain/status 查询当前状态。验证完成后,dns.status、cert.status 会变为 VERIFIED。对未连接自定义域名的 Web Hosting 调用状态查询时,将以 WGL404001 响应。
API
下列所有端点的基准 URL 均为 https://cma.weegloo.com/v1,Authorization 头需携带用于 CMA 认证的 Bearer 令牌。修改、部分修改为实现乐观并发控制,需同时发送 X-Weegloo-Version 头(当前资源的 sys.version)。创建、删除请求不带该头。
相关文档
- Upload API:上传静态文件 ZIP 以获得用于创建 Web Hosting 的 Upload 的请求。
- Space:Web Hosting 所属的 Space。
