端点

发布应用

把已保存的应用发布到网上,效果和 Publish 按钮一样。

POSThttps://www.setherion.com/api/v1/projects/{id}/publish

套餐: 所有套餐

把应用按已保存的样子发布到网上,经过的步骤和编辑器中的 Publish 按钮相同。以前发布过的应用会保留原来的地址;第一次发布的应用,会得到一个由应用名称生成的、位于 setherion.app 下的地址。

发布不消耗积分。你需要有修改该应用的权限。通过 API 发布,每个账户每天最多 100 次,手动操作的人不会达到这个数;编辑器自带的按钮没有这个限制。

请求

不需要请求体。

bash
curl -X POST https://www.setherion.com/api/v1/projects/7c1e4a52-9b0d-4f3e-8a61-2d5f0c9e7b14/publish \
  -H "Authorization: Bearer $SETHERION_API_KEY"

响应

json
{ "ok": true, "url": "https://coffee-shop.setherion.app", "ready": true }
字段类型含义
okboolean应用已发布时为 true。
urlstring应用上线的地址。
readyboolean地址仍在设置中时为 false。一两分钟内就会生效。

对同一个已保存的应用重复发布是安全的:第二次调用会返回相同的地址。

修改后再发布

发布的内容就是已保存的内容,而修改在完成时就会保存。所以先修改再发布,就能把改动发布到网上:

js
const base = 'https://www.setherion.com/api/v1/projects'
const headers = {
  Authorization: `Bearer ${process.env.SETHERION_API_KEY}`,
  'Content-Type': 'application/json',
}

const edit = await fetch(`${base}/${appId}/edit`, {
  method: 'POST',
  headers,
  body: JSON.stringify({ prompt: 'Add a contact form' }),
}).then(r => r.json())

if (edit.ok) {
  const live = await fetch(`${base}/${appId}/publish`, { method: 'POST', headers }).then(r => r.json())
  console.log(live.url)
}

错误

状态码出现时机
400应用的代码中包含机密,例如 API 密钥,因此没有发布。错误信息会指出位置。
401密钥缺失、错误或已被撤销。
404没有这个应用,或者你的密钥无法修改它。
409应用还没有代码,或者它需要的地址不可用,或者它是私有应用,不能放在你自己的域名上。错误信息会说明是哪一种。
429你今天已通过 API 发布了 100 次。计数明天重置。
502发布在我们这一侧失败了,或者主机上的构建失败了。请重试。
503发布暂时不可用。请一分钟后重试。
确切的提示语
状态码error
400Publishing would put a secret key on the open internet: ... 后面跟着机密的类型、文件和行号,以及应该怎么做。
404No such app on this account.
409This app has no code yet. Build it in Setherion first.
409The address coffee-shop.setherion.app belongs to another app. Choose a different one.
409Could not find a free address for this app. Rename it and publish again.
409This app is private, and a private app can only be published on its setherion.app address. To use a domain of your own, make it public first. Otherwise try again in a moment. Nothing was published.
429That is 100 publishes through the API today. The count resets tomorrow.
502The build failed on the host, so this version is not online. Publish again, and if it fails again, ask for a fix in the editor.
502The build was cancelled on the host, so this version is not online. Publish again.
503Publishing is briefly unavailable. Try again in a minute.

这个页面对你有帮助吗?

加入社区

提问、交流想法,看看别人在构建什么。