|
| 1 | +--- |
| 2 | +title: 将你的 Astro 站点部署到 Seenode |
| 3 | +description: 如何在 Seenode 上将你的 Astro 网站部署到网上。 |
| 4 | +sidebar: |
| 5 | + label: Seenode |
| 6 | +type: deploy |
| 7 | +i18nReady: true |
| 8 | +--- |
| 9 | +import { Steps } from '@astrojs/starlight/components'; |
| 10 | +import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'; |
| 11 | +import ReadMore from '~/components/ReadMore.astro'; |
| 12 | + |
| 13 | +[Seenode](https://seenode.com) 是一个用于构建和部署具有数据库、内置可观测性及自动扩展功能的 Web 应用部署平台。Astro 网站可通过服务端渲染(SSR)技术部署至 Seenode 平台。 |
| 14 | + |
| 15 | +本指南包含通过 Web 界面部署到 Seenode 的说明。 |
| 16 | + |
| 17 | +## 项目配置 |
| 18 | + |
| 19 | +### SSR 适配器 |
| 20 | + |
| 21 | +要在你的 Astro 项目中启用按需渲染并部署到 Seenode,使用 `astro add` 命令添加 [Node.js 适配器](/zh-cn/guides/integrations-guide/node/)。这将安装适配器并对你的 `astro.config.mjs` 文件进行相应更改。 |
| 22 | + |
| 23 | +<PackageManagerTabs> |
| 24 | + <Fragment slot="npm"> |
| 25 | + ```shell |
| 26 | + npx astro add node |
| 27 | + ``` |
| 28 | + </Fragment> |
| 29 | + <Fragment slot="pnpm"> |
| 30 | + ```shell |
| 31 | + pnpm astro add node |
| 32 | + ``` |
| 33 | + </Fragment> |
| 34 | + <Fragment slot="yarn"> |
| 35 | + ```shell |
| 36 | + yarn astro add node |
| 37 | + ``` |
| 38 | + </Fragment> |
| 39 | +</PackageManagerTabs> |
| 40 | + |
| 41 | +安装适配器后,更新你的 `astro.config.mjs` 并按 Seenode 的要求来配置服务器: |
| 42 | + |
| 43 | +```js title="astro.config.mjs" ins={6-11} |
| 44 | +import { defineConfig } from 'astro/config'; |
| 45 | +import node from '@astrojs/node'; |
| 46 | + |
| 47 | +export default defineConfig({ |
| 48 | + output: 'server', |
| 49 | + adapter: node({ |
| 50 | + mode: 'standalone' |
| 51 | + }), |
| 52 | + server: { |
| 53 | + port: process.env.NODE_ENV === 'production' ? (Number(process.env.PORT) || 80) : 4321, |
| 54 | + host: true |
| 55 | + } |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +更新你的 `package.json`,添加一个启动脚本来运行已构建的服务器: |
| 60 | + |
| 61 | +```json title="package.json" ins={6} |
| 62 | +{ |
| 63 | + "scripts": { |
| 64 | + "dev": "astro dev", |
| 65 | + "build": "astro build", |
| 66 | + "preview": "astro preview", |
| 67 | + "start": "NODE_ENV=production node ./dist/server/entry.mjs" |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +<ReadMore>请参考 [Seenode 的 Astro 部署指南](https://seenode.com/docs/frameworks/javascript/astro/) 了解更多配置选项和故障排除方法。</ReadMore> |
| 73 | + |
| 74 | +## 如何部署 |
| 75 | + |
| 76 | +你可以通过 Web 界面连接你的 Git 仓库,将项目部署到 Seenode。 |
| 77 | + |
| 78 | +### Web 界面部署 |
| 79 | + |
| 80 | +<Steps> |
| 81 | +1. 创建一个 [Seenode 账户](https://cloud.seenode.com) 并登录。 |
| 82 | + |
| 83 | +2. 推送代码到你的 Git 仓库(GitHub 或 GitLab)。 |
| 84 | + |
| 85 | +3. 从 [Seenode 控制面板](https://cloud.seenode.com/dashboard/applications/web/create) 创建一个新的 **Web 服务** 并连接你的仓库。 |
| 86 | + |
| 87 | +4. Seenode 会自动检测你的 Astro 项目。配置部署设置: |
| 88 | + - **构建命令:** `npm ci && npm run build` (或使用 `pnpm` / `yarn` 等效命令) |
| 89 | + - **启动命令:** `npm start` |
| 90 | + - **端口:** `80` (Web 服务必需) |
| 91 | + |
| 92 | +5. 选择你需要的实例大小并点击 **创建 Web 服务**。 |
| 93 | + |
| 94 | +6. 你的应用将被构建并部署。完成后,你将收到一个 URL 来访问你的 Astro 网站,之后你可以将你的域名绑定到该网站。 |
| 95 | +</Steps> |
| 96 | + |
| 97 | +## 官方资源 |
| 98 | + |
| 99 | +- [Seenode Cloud](https://cloud.seenode.com) — Seenode 控制面板 |
| 100 | +- [Seenode 文档](https://seenode.com/docs) — 完整的平台文档 |
| 101 | +- [Seenode Astro 指南](https://seenode.com/docs/frameworks/javascript/astro/) — 详细的部署指南和故障排除说明 |
| 102 | +- [Seenode Astro 模板](https://github.com/seenode/example-astro) — 预配置的启动模板 |
0 commit comments