howl/test/server.tsx
Chris Wanstrath 0cad100197 ________ ______ _______ ______ ________
/        |/      \ /       \  /      \ /        |
$$$$$$$$//$$$$$$  |$$$$$$$  |/$$$$$$  |$$$$$$$$/
$$ |__   $$ |  $$ |$$ |__$$ |$$ | _$$/ $$ |__
$$    |  $$ |  $$ |$$    $$< $$ |/    |$$    |
$$$$$/   $$ |  $$ |$$$$$$$  |$$ |$$$$ |$$$$$/
$$ |     $$ \__$$ |$$ |  $$ |$$ \__$$ |$$ |_____
$$ |     $$    $$/ $$ |  $$ |$$    $$/ $$       |
$$/       $$$$$$/  $$/   $$/  $$$$$$/  $$$$$$$$/
2026-01-16 08:33:38 -08:00

53 lines
1.2 KiB
TypeScript

import { Hono } from 'hono'
import { readdirSync } from 'fs'
import { join } from 'path'
import { capitalize } from './utils'
import { Layout, NavLink, NavList, NavItem } from './layout'
const port = process.env.PORT ?? '3100'
const app = new Hono()
app.get('/:file', async c => {
const file = c.req.param('file') ?? ''
const fileName = (file).replace('.', '')
const path = join(process.env.PWD ?? '.', `/src/${fileName}.tsx`)
if (!(await Bun.file(path).exists()))
return c.text('404 Not Found', 404)
const page = await import(path + `?t=${Date.now()}`)
return c.html(
<Layout title={`<${capitalize(file)} />`}>
<page.Test req={c.req} />
</Layout>
)
})
app.get('/', c => {
return c.html(
<Layout title="🐺 howl" showHomeLink={false}>
<NavList>
{testFiles().map(x => (
<NavItem key={x}>
<NavLink href={`/${x}`}>
{x}
</NavLink>
</NavItem>
))}
</NavList>
</Layout>
)
})
function testFiles(): string[] {
return readdirSync('./src')
.filter(x => x.endsWith('.tsx') && !x.startsWith('index'))
.map(x => x.replace('.tsx', ''))
.sort()
}
export default {
fetch: app.fetch,
port
}