Skip to content

Instantly share code, notes, and snippets.

View yusukebe's full-sized avatar
😃
Let's go!

Yusuke Wada yusukebe

😃
Let's go!
View GitHub Profile
import { render } from 'hono/jsx/dom'
import { hc } from 'hono/client'
import api from './api'
import useSWR from 'swr'
const client = hc<typeof api>('/api')
function App() {
const $get = client.index.$get
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Hono } from '../../hono'
import type { Env, H, HandlerResponse, Input, MiddlewareHandler } from '../../types'
type InitApp<E extends Env = Env> = (app: Hono<E>) => void
interface CreateHandlersInterface<E extends Env, P extends string> {
<I extends Input = {}, R extends HandlerResponse<any> = any>(handler1: H<E, P, I, R>): [
H<E, P, I, R>
]
import { Plugin } from 'vite'
import path from 'path'
import { parse } from '@babel/parser'
import _traverse, { NodePath } from '@babel/traverse'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const traverse = (_traverse.default as typeof _traverse) ?? _traverse
import _generate from '@babel/generator'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { AsyncLocalStorage } from 'node:async_hooks'
const useStorage = <E extends unknown>() => {
const localStorage = new AsyncLocalStorage()
return {
store: <T>(env: E, callback: () => T): T => {
return localStorage.run(env, callback)
},
get: (key: keyof E) => {
const store = localStorage.getStore() as E
import { Hono } from 'hono'
import { streamText } from 'hono/streaming'
import { Ai } from '@cloudflare/ai'
import { events } from 'fetch-event-stream'
type Bindings = {
AI: any
}
const app = new Hono<{ Bindings: Bindings }>()
import { getPlatformProxy } from 'wrangler'
const { env, dispose } = await getPlatformProxy()
console.log(env.AI) // undefined !
await dispose()
// node ./get-platform-proxy-with-ai.mjs
// app/routes/_middleware.ts
import { createRoute } from 'honox/factory'
export default createRoute(async (c, next) => {
console.log('middleware at app/routes/_middleware.ts')
await next()
})
// app/routes/echo/_title.island.tsx
import { useEffect, useState } from 'hono/jsx'
import { hc } from 'hono/client'
import type { Hono } from 'hono'
import api from './api'
export const apiClient = <T extends Hono>(path: string = './api') => {
let url: string | undefined
if (globalThis.window) {
url = new URL(path, window.location.href + '/').toString()
type MethodOverrideOptions = {
// Default is 'form' and the value is `_method`
form?: string
header?: string
query?: string
}
const DEFAULT_METHOD_FORM_NAME = '_method'
const methodOverride = (options?: MethodOverrideOptions): MiddlewareHandler =>
let code1 = `
import { Hono } from 'hono'
const app = new Hono()
const routes = app
`
for (let i = 1; i < 300; i++) {
code1 += `.get('/route${i}', (c) => {