This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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> | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getPlatformProxy } from 'wrangler' | |
const { env, dispose } = await getPlatformProxy() | |
console.log(env.AI) // undefined ! | |
await dispose() | |
// node ./get-platform-proxy-with-ai.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { |
NewerOlder