An open API service indexing awesome lists of open source software.

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

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)
```