Appearance
Vercel
Vercel 是 AI 云,提供开发者工具和云基础设施,以构建、扩展和保护更快、更个性化的 Web 服务。
🌐 Vercel is the AI cloud, providing the developer tools and cloud infrastructure to build, scale, and secure a faster, more personalized web.
Hono 无需配置即可部署到 Vercel。
🌐 Hono can be deployed to Vercel with zero-configuration.
1. 设置
🌐 1. Setup
Vercel 的入门模板已可用。 使用 "create-hono" 命令启动你的项目。 本示例请选择 vercel 模板。
🌐 A starter for Vercel is available. Start your project with "create-hono" command. Select vercel template for this example.
sh
npm create hono@latest my-appsh
yarn create hono my-appsh
pnpm create hono my-appsh
bun create hono@latest my-appsh
deno init --npm hono my-app进入 my-app 并安装依赖。
🌐 Move into my-app and install the dependencies.
sh
cd my-app
npm ish
cd my-app
yarnsh
cd my-app
pnpm ish
cd my-app
bun i在下一步中,我们将使用 Vercel CLI 在本地进行应用开发。如果你还没有安装,请按照 Vercel CLI 文档 全局安装它。
🌐 We will use Vercel CLI to work on the app locally in the next step. If you haven't already, install it globally following the Vercel CLI documentation.
2. 你好,世界
🌐 2. Hello World
在你项目的 index.ts 或 src/index.ts 中,将 Hono 应用作为默认导出。
🌐 In the index.ts or src/index.ts of your project, export the Hono application as a default export.
ts
import { Hono } from 'hono'
const app = new Hono()
const welcomeStrings = [
'Hello Hono!',
'To learn more about Hono on Vercel, visit https://vercel.com/docs/frameworks/backend/hono',
]
app.get('/', (c) => {
return c.text(welcomeStrings.join('\n\n'))
})
export default app如果你使用 vercel 模板开始,这已经为你设置好了。
🌐 If you started with the vercel template, this is already set up for you.
3. 跑
🌐 3. Run
要在本地运行开发服务器:
🌐 To run the development server locally:
sh
vercel dev访问 localhost:3000 将会得到一个文本响应。
🌐 Visiting localhost:3000 will respond with a text response.
4. 部署
🌐 4. Deploy
使用 vc deploy 部署到 Vercel。
🌐 Deploy to Vercel using vc deploy.
sh
vercel deploy延伸阅读
🌐 Further reading