跳到正文
DEV Community· Ciro Cesar Maciel·· 4 天前AI 評分58

如何透過 Hoster 發布 Claude Code 建置的網站而無須設定伺服器

How to publish a site built with Claude Code without setting up a server

AI 導讀

文章示範如何透過 Hoster,將 Claude Code 建置的靜態網站發布到 HTTPS 網址,而毋須自行設定伺服器。Claude Code 在本機執行建置,再透過 MCP 授權並以 CLI 直接上傳 dist 或 build 資料夾;Hoster 不支援伺服器端建置、SSR 或函數。每次部署會更新同一網址,Hoster 預設保留最近 5 個版本供回退;自訂網域則透過一個 CNAME 設定。

正文

Claude Code built the site, it runs on localhost, and now you want to send the link to someone. Most tutorials jump to servers, certificates, connecting GitHub to a dashboard and configuring a remote build. For a site Claude Code generated, you need almost none of that: after the build it is a folder of finished files, and that folder only needs a place that serves it over HTTPS.

This is the path with Hoster, from the Infrastructure line (by Ciro Cesar Maciel, who writes this): an MCP server Claude Code connects to with a browser sign-in, and one command that uploads the build.

First: is it a static site?

Almost always. A Vite, React, Astro or plain HTML project ends up, after the build, as a dist or build folder with HTML, CSS, JavaScript and images. Hoster publishes exactly that folder. It does not run your build: Claude Code does that locally (npm run build, bun run build, whatever package.json says).

If the project has API routes, server-side rendering or functions that run on every request, that part is not static, and Hoster is not for it.

Step 1: connect Claude Code to Hoster

claude mcp add --transport http hoster https://hoster.worker.myinfrastructure.click/mcp

No key in the command, no secret in a config file. The first call answers 401, Claude Code discovers the authorization server, opens the browser, and you sign in with a code sent to your e-mail. The server address is the same for the whole account; there is no project id in it. /mcp inside Claude Code shows whether hoster is connected.

Step 2: ask for the deploy

Say it in words: "build and publish the dist folder to Hoster as project my-site". Behind that:

  1. Claude Code runs the build and checks where the folder landed.
  2. It creates the project my-site if it does not exist. The project name is the subdomain.
  3. It calls hoster_deploy_ticket, and Hoster returns a ready command: bunx @ciromaciel/hoster-cli push ht_… --dir ./dist.
  4. Claude Code runs that command in your terminal, with your permission. The files go from your disk straight to Hoster; they never pass through the conversation.
  5. It checks the deploy status and answers with the address.

The ticket is good for one project, one use and 15 minutes. If an upload fails halfway, run the same command again.

Why two parts? The MCP server is remote and cannot reach your disk, so it authorizes and the local command sends the bytes.

Step 3: open it

The site answers at https://my-site.myhoster.click, with HTTPS from the first second: there is no certificate to wait for.

To update, ask again. Every deploy is a new version at the same address. If the new one broke something, ask to roll back: Hoster switches the active version without re-uploading, and keeps the last 5 by default.

A custom domain is one CNAME to proxy.hoster.myinfrastructure.click, and Hoster issues its certificate too.

What usually goes wrong

  • SPA route returns 404 on reload. Hoster serves the project's main file for paths without an extension, which is what makes React Router work. A 404.html at the root of the build turns that fallback off.
  • CSS and JS return 404. The upload pointed at the repository root instead of the build folder.
  • I deployed and still see the old site. The new version reaches the edge within a minute; with the most aggressive cache strategy, returning visitors keep the HTML longer. The balanced strategy revalidates HTML on every load.
  • A secret in an environment variable. Hoster's variables are public, read by the browser from window.ENV.

What Hoster does not do

No server-side build, no functions or SSR, no push-to-deploy from Git, no preview per branch, no _redirects or vercel.json. If you need those, Vercel, Netlify and Cloudflare Pages build remotely and run functions. Hoster is for when the folder is ready and you want the address without configuring anything.

Honest notes

  • No API key is needed through MCP. The hk_ key is for using the CLI on your own, for example in CI, and it is on the Pro and Scale plans.
  • An account without a plan has one project, and it publishes. Plans add projects.
  • The Hoster dashboard has English (Language in the account menu); some screens of the line are still Portuguese.

Full reference for people and agents: https://myinfrastructure.click/products/hoster/llms.txt

來源:DEV Community · dev.to