https://github.com/jcs224/hono_inertia
Inertia.js adapter for Hono
https://github.com/jcs224/hono_inertia
deno hacktoberfest hono inertia inertiajs
Last synced: 2 months ago
JSON representation
Inertia.js adapter for Hono
- Host: GitHub
- URL: https://github.com/jcs224/hono_inertia
- Owner: jcs224
- License: mit
- Created: 2023-02-10T09:01:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-19T04:55:49.000Z (about 2 years ago)
- Last Synced: 2025-07-14T20:10:23.228Z (3 months ago)
- Topics: deno, hacktoberfest, hono, inertia, inertiajs
- Language: TypeScript
- Homepage:
- Size: 4.88 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Inertia.js Adapter for Hono
[Inertia.js](https://inertiajs.com) adapter for [Hono](https://honojs.dev). Only for Deno right now, coming soon to other runtimes supported by Hono (CF Workers, Bun, etc.)
## Example (in Deno)
```js
import { serve } from 'https://deno.land/std/http/mod.ts'
import { Hono } from 'https://deno.land/x/hono/mod.ts'
import { inertia } from 'https://deno.land/x/hono_inertia/mod.ts'const app = new Hono()
// Provide a template string
// Put '@inertia' somewhere in the body, which will be replaced by the Inertia bootstrapping frontend code
const template = `
Inertia Hono@inertia
`
// Optional function to determine Inertia version
const checkVersion = () => {
return Deno.env.get('OPTIONAL_INERTIA_VERSION')
}// Add Inertia middleware with applied options to global Hono middleware stack
app.use('*', inertia(template, checkVersion))// use the 'render()' method now attached to Hono to render an Inertia page
app.get('/', (c, next) => {
const componentName = 'HomePage'
const payloadObject = {
username: 'johndoe',
email: 'jdizzle@example.com'
}return c.get('inertia').render(componentName, payloadObject)
})serve(app.fetch)
```