Skip to content

Fastly 计算

¥Fastly Compute

Fastly 计算 是一个高级的边缘计算系统,它使用你喜欢的语言在我们的全球边缘网络上运行你的代码。Hono 也适用于 Fastly Compute。

¥Fastly Compute is an advanced edge computing system that runs your code, in your favorite language, on our global edge network. Hono also works on Fastly Compute.

你可以在本地开发应用并使用 Fastly CLI 使用几个命令发布它。

¥You can develop the application locally and publish it with a few commands using Fastly CLI.

1. 设置

¥ Setup

Fastly Compute 的启动器可用。使用 "create-hono" 命令启动你的项目。为此示例选择 fastly 模板。

¥A starter for Fastly Compute is available. Start your project with "create-hono" command. Select fastly 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 to 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

2. Hello World

编辑 src/index.ts

¥Edit src/index.ts:

ts
// src/index.ts
import { Hono } from 'hono'
const app = new Hono()

app.get('/', (c) => c.text('Hello Fastly!'))

app.fire()

3. 运行

¥ Run

在本地运行开发服务器。然后,在你的 Web 浏览器中访问 http://localhost:7676

¥Run the development server locally. Then, access http://localhost:7676 in your Web browser.

sh
npm run start
sh
yarn start
sh
pnpm run start
sh
bun run start

4. 部署

¥ Deploy

要构建你的应用并将其部署到你的 Fastly 账户,请输入以下命令。首次部署应用时,系统将提示你在账户中创建新服务。

¥To build and deploy your application to your Fastly account, type the following command. The first time you deploy the application, you will be prompted to create a new service in your account.

如果你还没有账户,则必须拥有 创建你的 Fastly 账户

¥If you don't have an account yet, you must create your Fastly account.

sh
npm run deploy
sh
yarn deploy
sh
pnpm run deploy
sh
bun run deploy

Hono v4.8 中文网 - 粤ICP备13048890号