Skip to content

Fastly 计算

¥Fastly Compute

Fastly 的计算 产品允许我们构建高规模、全球分布的应用并在 Fastly CDN 边缘执行代码。

¥Fastly's Compute offering allows us to build high scale, globally distributed applications and execute code at the edge of Fastly CDN.

Hono 也适用于 Fastly Compute。

¥Hono also works on Fastly Compute.

1. 安装 CLI

¥ Install CLI

要使用 Fastly Compute,如果你还没有 创建一个 Fastly 账户,则必须有 创建一个 Fastly 账户。然后,安装 Fastly CLI

¥To use Fastly Compute, you must create a Fastly account if you don't already have one. Then, install Fastly CLI.

macOS

sh
brew install fastly/tap/fastly

其他操作系统请点击此链接:

¥Follow this link for other OS:

2. 设置

¥ 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

3. 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()

4. 运行

¥ Run

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

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

sh
npm run dev
sh
yarn dev
sh
pnpm dev
sh
bun run dev

4. 部署

¥ Deploy

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

就这些!!

¥That's all!!

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