HTML
Learn how to serve HTML content and use JSX/TSX with Hono
Introduction
Hono - means flame🔥 in Japanese - is a small, simple, and ultrafast web framework built on Web Standards.
Project
Let’s create a new Hono project using Bun.
A starter for Netlify is available.
Start your project with “create-hono” command selecting netlify template:
Move into hono-html directory.
Add dependencies:
Edge function
The file netlify/edge-functions/index.ts contains the code for your edge function.
This is where you will write your Hono application.
Update the import statements (delete @jsr):
'/', return 'Hello Hono!'
})
import { Hono } from 'hono'imports the coreHonoclass from the framework. This is the entry point for building any Hono application: it provides the methods to define routes (app.get(),app.post(), etc.) and middleware.import { handle } from 'hono/netlify'imports the Netlify adapter. Thehandlefunction wraps your Hono app so it can run as a Netlify Edge Function, translating between Netlify’s request/response format and Hono’s.new Hono()creates a new application instance where you register all your routes.app.get('/', (c) => ...)registers a handler forGETrequests to the root path/. The callback receives a context objectc, which provides methods to build responses:c.text()returns a plain text response,c.html()returns HTML,c.json()returns JSON, etc.export default handle(app)exports the adapted app as the default export, which is what Netlify expects from an edge function.
Server
Run the development server with Netlify CLI.
Estás leyendo una vista previa.
Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.
Iniciar sesión