Compare commits

...

2 Commits

Author SHA1 Message Date
c29a4092ca 0.0.13 2026-03-27 16:54:38 -07:00
ed6dff6639 Add ping endpoint and tsconfig for live-reload 2026-03-27 16:54:30 -07:00
5 changed files with 40 additions and 3 deletions

View File

@ -3,6 +3,6 @@ export default () => (
<h1>Live Reload Demo</h1> <h1>Live Reload Demo</h1>
<p>Run this with <code>bun run dev</code>, then edit this file.</p> <p>Run this with <code>bun run dev</code>, then edit this file.</p>
<p>The browser will automatically refresh no manual reload needed.</p> <p>The browser will automatically refresh no manual reload needed.</p>
<p class="hint">Try changing this text and saving!</p> <p class="hint">OMG! Try changing this text and saving!</p>
</section> </section>
) )

View File

@ -0,0 +1,36 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": [
"ESNext",
"DOM"
],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false,
"baseUrl": ".",
"paths": {
"#*": [
"src/*"
]
},
}
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@because/hype", "name": "@because/hype",
"version": "0.0.12", "version": "0.0.13",
"module": "src/index.tsx", "module": "src/index.tsx",
"type": "module", "type": "module",
"exports": { "exports": {

View File

@ -146,6 +146,7 @@ export class Hype<
// live reload endpoint (dev mode only) // live reload endpoint (dev mode only)
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
this.sse('/__hype/reload', () => {}) this.sse('/__hype/reload', () => {})
this.get('/__hype/ping', c => c.text('ok'))
} }
// healthcheck // healthcheck

View File

@ -23,7 +23,7 @@ const Layout: FC = ({ children, title, props }) =>
</body> </body>
</html> </html>
const RELOAD_SCRIPT = '{let c=false;const e=new EventSource("/__hype/reload");e.onopen=()=>{if(c)location.reload();c=true};e.onerror=()=>{e.close();let d=50;setTimeout(function r(){fetch("/__hype/reload").then(()=>location.reload()).catch(()=>{d=Math.min(d*1.5,2000);setTimeout(r,d)})},d)}}' const RELOAD_SCRIPT = '{let c=false;const e=new EventSource("/__hype/reload");e.onopen=()=>{if(c)location.reload();c=true};e.onerror=()=>{e.close();let d=50;setTimeout(function r(){fetch("/__hype/ping").then(()=>location.reload()).catch(()=>{d=Math.min(d*1.5,2000);setTimeout(r,d)})},d)}}'
export const ReloadScript: FC = () => export const ReloadScript: FC = () =>
isDev ? <script dangerouslySetInnerHTML={{ __html: RELOAD_SCRIPT }} /> : null isDev ? <script dangerouslySetInnerHTML={{ __html: RELOAD_SCRIPT }} /> : null