Bugfix watcher function. Refresh bundler after adding and removing pages
This commit is contained in:
@@ -1,66 +1,19 @@
|
||||
import path from "path";
|
||||
import type { RouterTypes, ServeOptions } from "bun";
|
||||
import type { ServeOptions } from "bun";
|
||||
import grabAppPort from "../../utils/grab-app-port";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import handleWebPages from "./web-pages/handle-web-pages";
|
||||
import handleRoutes from "./handle-routes";
|
||||
import isDevelopment from "../../utils/is-development";
|
||||
import type { Server } from "http";
|
||||
|
||||
type Params = {
|
||||
dev?: boolean;
|
||||
};
|
||||
|
||||
// type ServerOptions = Omit<ServeOptions, "fetch"> & {
|
||||
// routes: { [K: string]: RouterTypes.RouteValue<string> };
|
||||
// fetch?: (
|
||||
// this: Server,
|
||||
// request: Request,
|
||||
// server: Server,
|
||||
// ) => Response | Promise<Response>;
|
||||
// };
|
||||
|
||||
export default async function (params?: Params): Promise<ServeOptions> {
|
||||
const port = grabAppPort();
|
||||
const { PUBLIC_DIR } = grabDirNames();
|
||||
|
||||
// const opts: ServerOptions = {
|
||||
// routes: {
|
||||
// "/__hmr": {
|
||||
// async GET(req) {
|
||||
// if (!isDevelopment()) {
|
||||
// return new Response(`Production Environment`);
|
||||
// }
|
||||
|
||||
// let controller: ReadableStreamDefaultController<string>;
|
||||
// const stream = new ReadableStream<string>({
|
||||
// start(c) {
|
||||
// controller = c;
|
||||
// global.HMR_CONTROLLERS.add(c);
|
||||
// },
|
||||
// cancel() {
|
||||
// global.HMR_CONTROLLERS.delete(controller);
|
||||
// },
|
||||
// });
|
||||
|
||||
// return new Response(stream, {
|
||||
// headers: {
|
||||
// "Content-Type": "text/event-stream",
|
||||
// "Cache-Control": "no-cache",
|
||||
// Connection: "keep-alive",
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// },
|
||||
// "/api/*": {},
|
||||
// "/*": {
|
||||
// async GET(req) {
|
||||
// return await handleWebPages({ req });
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
|
||||
return {
|
||||
async fetch(req, server) {
|
||||
try {
|
||||
@@ -72,17 +25,11 @@ export default async function (params?: Params): Promise<ServeOptions> {
|
||||
);
|
||||
const match = global.ROUTER.match(referer_url.pathname);
|
||||
|
||||
if (!match?.filePath) {
|
||||
return new Response(`Unhandled Path.`);
|
||||
}
|
||||
|
||||
const target_map = global.BUNDLER_CTX_MAP?.find(
|
||||
(m) => m.local_path == match.filePath,
|
||||
);
|
||||
|
||||
if (!target_map?.entrypoint) {
|
||||
return new Response(`Target Path has no map`);
|
||||
}
|
||||
const target_map = match?.filePath
|
||||
? global.BUNDLER_CTX_MAP?.find(
|
||||
(m) => m.local_path == match.filePath,
|
||||
)
|
||||
: undefined;
|
||||
|
||||
let controller: ReadableStreamDefaultController<string>;
|
||||
const stream = new ReadableStream<string>({
|
||||
|
||||
Reference in New Issue
Block a user