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. 设置
¥ 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-app
sh
yarn create hono my-app
sh
pnpm create hono my-app
sh
bun create hono@latest my-app
sh
deno init --npm hono my-app
移入 my-app
并安装依赖。
¥Move into my-app
and install the dependencies.
sh
cd my-app
npm i
sh
cd my-app
yarn
sh
cd my-app
pnpm i
sh
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. 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/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. 运行
¥ Run
要在本地运行开发服务器:
¥To run the development server locally:
sh
vercel dev
访问 localhost:3000
将返回文本响应。
¥Visiting localhost:3000
will respond with a text response.
4. 部署
¥ Deploy
使用 vc deploy
部署到 Vercel。
¥Deploy to Vercel using vc deploy
.
sh
vercel deploy
延伸阅读
¥Further reading