Publishing
Publishing deploys a page snapshot to PageGun's global CDN (Cloudflare R2). Once published, the page is publicly accessible at its configured URL.
How Publishing Works
When you publish a page, PageGun:
- Takes a snapshot of the current page content
- Uploads to CDN — The rendered page is stored on Cloudflare R2
- Updates the page index — The project's page manifest is regenerated
- Enables Data Mode encryption — If Data Mode is active, content is encrypted before upload
Pages start as drafts. They're only visible publicly after being explicitly published.
Draft → Publish → Live on CDN
↕
Unpublish → Removed from CDNPublish a Page
POST /v1/pages/publishPublishes a page to CDN, making it publicly accessible.
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
pageId | string | Yes | ID of the page to publish |
Request
curl -X POST https://api.pagegun.com/v1/pages/publish \
-H "Authorization: Bearer pgk_live_xxxxx" \
-H "Content-Type: application/json" \
-d '{"pageId": "DgTgGtE9"}'const response = await fetch("https://api.pagegun.com/v1/pages/publish", {
method: "POST",
headers: {
Authorization: "Bearer pgk_live_xxxxx",
"Content-Type": "application/json",
},
body: JSON.stringify({ pageId: "DgTgGtE9" }),
});
const { data } = await response.json();Response
{
"success": true,
"data": {
"page_id": "DgTgGtE9",
"status": "published",
"published_at": "2024-03-15T14:30:00Z"
}
}Unpublish a Page
POST /v1/pages/unpublishRemoves a page from CDN. The page content is preserved but no longer publicly accessible.
Request Body
| Name | Type | Required | Description |
|---|---|---|---|
pageId | string | Yes | ID of the page to unpublish |
Request
curl -X POST https://api.pagegun.com/v1/pages/unpublish \
-H "Authorization: Bearer pgk_live_xxxxx" \
-H "Content-Type: application/json" \
-d '{"pageId": "DgTgGtE9"}'const response = await fetch("https://api.pagegun.com/v1/pages/unpublish", {
method: "POST",
headers: {
Authorization: "Bearer pgk_live_xxxxx",
"Content-Type": "application/json",
},
body: JSON.stringify({ pageId: "DgTgGtE9" }),
});
const { data } = await response.json();Response
{
"success": true,
"data": {
"page_id": "DgTgGtE9",
"status": "unpublished"
}
}Complete Workflow Example
Here's a full example: create a page, add content, and publish it.
const API_KEY = "pgk_live_xxxxx";
const BASE_URL = "https://api.pagegun.com/v1";
async function api(method: string, path: string, body?: object) {
const response = await fetch(`${BASE_URL}${path}`, {
method,
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: body ? JSON.stringify(body) : undefined,
});
return response.json();
}
// 1. Create a page
const { data: page } = await api("POST", "/pages", {
project_id: "MgdGoare",
page_name: "Changelog",
slug: "changelog",
type: "doc",
markdown_content: "# Changelog\n\n## v1.0.0\n\n- Initial release",
});
console.log(`Created page: ${page.id}`);
// 2. Publish it
await api("POST", "/pages/publish", { pageId: page.id });
console.log("Page is now live!");
// 3. Update content later
await api("PUT", `/pages/${page.id}`, {
markdown_content: "# Changelog\n\n## v1.1.0\n\n- New feature\n\n## v1.0.0\n\n- Initial release",
});
// 4. Republish with updated content
await api("POST", "/pages/publish", { pageId: page.id });
console.log("Updated page republished!");