live reaload

main
Ethan Niser 2023-09-14 16:38:04 -05:00
parent cb6a1d0c6c
commit 80c5863e0b
6 changed files with 17 additions and 8 deletions

Binary file not shown.

@ -3,8 +3,8 @@
"module": "src/main.ts",
"type": "module",
"scripts": {
"dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\"",
"liveReload": "bun run --hot src/dev/liveReload.ts",
"dev": "concurrently \"bun run --hot src/main.ts\" \"bun run uno:dev\" \"bun run liveReload\"",
"liveReload": "bun run src/lib/dev/liveReload.ts",
"start": "bun run uno && bun run src/main.ts",
"db:push": "bunx drizzle-kit push:sqlite",
"db:studio": "bunx drizzle-kit studio",
@ -29,7 +29,6 @@
"@libsql/client": "^0.3.4",
"@lucia-auth/adapter-sqlite": "^2.0.0",
"@t3-oss/env-core": "^0.6.1",
"chokidar": "^3.5.3",
"drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1",
"elysia": "^0.6.22",

@ -24,7 +24,6 @@ export const BaseHtml = ({ children }: Html.PropsWithChildren) => (
};
socket.onmessage = function(event) {
console.log(event.data);
location.reload();
};

@ -1,15 +1,14 @@
import { Elysia, ws } from "elysia";
import { type ElysiaWS } from "elysia/ws";
import { watch } from "chokidar";
let wsConnections = new Set<ElysiaWS<any>>();
watch("src/**/*.{ts,tsx}").on("all", (event, path) => {
console.log("sending event");
function dispatch() {
wsConnections.forEach((connection) => {
console.log("sending refresh");
connection.send("refresh");
});
});
}
const app = new Elysia()
.use(ws())
@ -26,6 +25,10 @@ const app = new Elysia()
console.log("message", message);
},
})
.get("/restart", () => {
console.log("recieved restart");
dispatch();
})
.listen(3001);
console.log(

@ -3,6 +3,7 @@ import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { api } from "./controllers";
import { autoroutes } from "elysia-autoroutes";
import { config } from "./config";
const app = new Elysia({
name: "@app/main",
@ -16,6 +17,12 @@ const app = new Elysia({
routesDir: "./pages",
})
)
.onStart(() => {
if (config.env.NODE_ENV === "development") {
void fetch("http://localhost:3001/restart");
console.log("🦊 Triggering Live Reload");
}
})
.listen(3000);
export type App = typeof app;