@flight-framework/cli 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -914,6 +914,65 @@ async function devCommand(options) {
914
914
  if (bundler && typeof bundler.createDevServer === "function") {
915
915
  consola2.info(`Using bundler: ${bundler.name || bundler.bundler || "custom"}`);
916
916
  const devServer = await bundler.createDevServer(config);
917
+ const transformPort = devServer.port;
918
+ const http = await import("http");
919
+ const fs = await import("fs/promises");
920
+ const path = await import("path");
921
+ const indexHtmlPath = path.join(root, "index.html");
922
+ const publicIndexPath = path.join(root, "public", "index.html");
923
+ const server = http.createServer(async (req, res) => {
924
+ const url = req.url || "/";
925
+ if (url === "/" || url === "/index.html" || !url.includes(".") && !url.startsWith("/@") && !url.startsWith("/__")) {
926
+ try {
927
+ let htmlContent;
928
+ try {
929
+ htmlContent = await fs.readFile(indexHtmlPath, "utf-8");
930
+ } catch {
931
+ htmlContent = await fs.readFile(publicIndexPath, "utf-8");
932
+ }
933
+ if (!htmlContent.includes("/__flightpack/hmr-runtime.js")) {
934
+ htmlContent = htmlContent.replace(
935
+ "</body>",
936
+ `<script src="/__flightpack/hmr-runtime.js"></script>
937
+ </body>`
938
+ );
939
+ }
940
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
941
+ res.end(htmlContent);
942
+ } catch (err) {
943
+ res.writeHead(404, { "Content-Type": "text/plain" });
944
+ res.end(`index.html not found in ${root}`);
945
+ }
946
+ return;
947
+ }
948
+ const proxyReq = http.request(
949
+ {
950
+ hostname: "localhost",
951
+ port: transformPort,
952
+ path: url,
953
+ method: req.method,
954
+ headers: req.headers
955
+ },
956
+ (proxyRes) => {
957
+ res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
958
+ proxyRes.pipe(res);
959
+ }
960
+ );
961
+ proxyReq.on("error", (err) => {
962
+ console.error("[CLI Proxy Error]", err.message);
963
+ res.writeHead(502, { "Content-Type": "text/plain" });
964
+ res.end("FlightPack transform server unavailable");
965
+ });
966
+ req.pipe(proxyReq);
967
+ });
968
+ const cliPort = port;
969
+ await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));
970
+ console.log(`
971
+ \u26A1 Flight dev server running
972
+ `);
973
+ console.log(` Bundler: FlightPack`);
974
+ console.log(` Local: http://localhost:${cliPort}`);
975
+ console.log(``);
917
976
  const elapsed = Date.now() - startTime;
918
977
  consola2.success(`Flight dev server ready in ${elapsed}ms`);
919
978
  devServer.printUrls?.();