H
Honoβ€’4mo ago
jamesfoley

Live Reload With Deno

I am using the Deno runtime with Hono and I was looking for a way to add live reload. I have searched for module but with little success. Can anyone point me in the direction of a resource so I can get the browser to refresh on save? Cheers Jim
9 Replies
blurSkye πŸ‡΅πŸ‡ΈπŸ‰
i made something like that for bun.js
import { createBunWebSocket, } from 'hono/bun'
import type { UpgradeWebSocket } from './node_modules/hono/dist/types/helper/websocket';
interface BunServerWebSocket<T> {
send(data: string | ArrayBufferLike, compress?: boolean): void;
close(code?: number, reason?: string): void;
data: T;
readyState: 0 | 1 | 2 | 3;
}
interface BunWebSocketHandler<T> {
open(ws: BunServerWebSocket<T>): void;
close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
message(ws: BunServerWebSocket<T>, message: string | Uint8Array): void;
}

export interface BunWebSocketData {
connId: number;
url: URL;
protocol: string;
}

const { upgradeWebSocket, websocket }: { upgradeWebSocket: UpgradeWebSocket, websocket: BunWebSocketHandler<BunWebSocketData> } = createBunWebSocket();

export { upgradeWebSocket, websocket };
import { createBunWebSocket, } from 'hono/bun'
import type { UpgradeWebSocket } from './node_modules/hono/dist/types/helper/websocket';
interface BunServerWebSocket<T> {
send(data: string | ArrayBufferLike, compress?: boolean): void;
close(code?: number, reason?: string): void;
data: T;
readyState: 0 | 1 | 2 | 3;
}
interface BunWebSocketHandler<T> {
open(ws: BunServerWebSocket<T>): void;
close(ws: BunServerWebSocket<T>, code?: number, reason?: string): void;
message(ws: BunServerWebSocket<T>, message: string | Uint8Array): void;
}

export interface BunWebSocketData {
connId: number;
url: URL;
protocol: string;
}

const { upgradeWebSocket, websocket }: { upgradeWebSocket: UpgradeWebSocket, websocket: BunWebSocketHandler<BunWebSocketData> } = createBunWebSocket();

export { upgradeWebSocket, websocket };
blurSkye πŸ‡΅πŸ‡ΈπŸ‰
it finds all the route.ts file and adds to the generateServer.ts
No description
blurSkye πŸ‡΅πŸ‡ΈπŸ‰
btw there is a reason it doesnt use file watcher, they somehow dont always detect changes 100% the time dont waste time trying different watchers like me
blurSkye πŸ‡΅πŸ‡ΈπŸ‰
such a structure will generate code like this, hopefully it makes sense
No description
jamesfoley
jamesfoleyOPβ€’4mo ago
Thanks @blurSkye πŸ‡΅πŸ‡ΈπŸ‰, I will try and get something like it for Deno. If I get stuck would you be willing to take a look at my work and offer some guidance? Thanks for what you provided.
blurSkye πŸ‡΅πŸ‡ΈπŸ‰
well bun is just objectively superior, it is faster, no reason i see to not use bun check hono.js docs remove bunjs specific bits like bun.serve and shit, i suppose deno doesnt need anyh of those, it works without that @jamesfoleythere is no feature expected to be coming from hono team regarding live reload, you will have make a adapter that reloads live for you, thats that,, so add the solved tag or just use nodemon like tool
jamesfoley
jamesfoleyOPβ€’4mo ago
Thanks @blurSkye πŸ‡΅πŸ‡ΈπŸ‰ for the help greatly appreciated.
Want results from more Discord servers?
Add your server