@flight-framework/cli 0.4.5 → 0.4.7

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
@@ -922,7 +922,8 @@ async function devCommand(options) {
922
922
  const publicIndexPath = path.join(root, "public", "index.html");
923
923
  const server = http.createServer(async (req, res) => {
924
924
  const url = req.url || "/";
925
- if (url === "/" || url === "/index.html" || !url.includes(".") && !url.startsWith("/@") && !url.startsWith("/__")) {
925
+ const isSpaRoute = url === "/" || url === "/index.html" || !url.includes(".") && !url.startsWith("/@") && !url.startsWith("/__") && !url.startsWith("/src/") && !url.startsWith("/node_modules/");
926
+ if (isSpaRoute) {
926
927
  try {
927
928
  let htmlContent;
928
929
  try {
@@ -945,7 +946,7 @@ async function devCommand(options) {
945
946
  }
946
947
  return;
947
948
  }
948
- const proxyRequest = (targetUrl, originalRes, attemptExtensions = false) => {
949
+ const proxyRequest = async (targetUrl, originalRes) => {
949
950
  const proxyReq = http.request(
950
951
  {
951
952
  hostname: "localhost",
@@ -954,45 +955,38 @@ async function devCommand(options) {
954
955
  method: req.method,
955
956
  headers: req.headers
956
957
  },
957
- (proxyRes) => {
958
- if (proxyRes.statusCode !== 404 || !attemptExtensions) {
958
+ async (proxyRes) => {
959
+ if (proxyRes.statusCode !== 404) {
959
960
  res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
960
961
  proxyRes.pipe(res);
961
962
  return;
962
963
  }
963
- proxyRes.resume();
964
- const commonExtensions = [".mjs", ".js", ".ts", ".tsx", ".jsx", "/index.js"];
965
- const tryNextExtension = (index) => {
966
- if (index >= commonExtensions.length) {
964
+ if (targetUrl.startsWith("/node_modules/")) {
965
+ proxyRes.resume();
966
+ try {
967
+ const { createRequire } = await import("module");
968
+ const require2 = createRequire(root + "/");
969
+ const importPath = targetUrl.replace("/node_modules/", "");
970
+ const resolvedPath = require2.resolve(importPath);
971
+ const content = await fs.readFile(resolvedPath);
972
+ let contentType = "application/javascript";
973
+ if (resolvedPath.endsWith(".json")) contentType = "application/json";
974
+ if (resolvedPath.endsWith(".css")) contentType = "text/css";
975
+ res.writeHead(200, {
976
+ "Content-Type": contentType,
977
+ "Access-Control-Allow-Origin": "*",
978
+ "Cache-Control": "no-cache"
979
+ });
980
+ res.end(content);
981
+ return;
982
+ } catch (resolveError) {
967
983
  res.writeHead(404, proxyRes.headers);
968
984
  res.end("Not Found");
969
985
  return;
970
986
  }
971
- const ext = commonExtensions[index];
972
- const fallbackUrl = targetUrl + ext;
973
- const fallbackReq = http.request(
974
- {
975
- hostname: "localhost",
976
- port: transformPort,
977
- path: fallbackUrl,
978
- method: "GET",
979
- // Always GET for fallbacks
980
- headers: req.headers
981
- },
982
- (fallbackRes) => {
983
- if (fallbackRes.statusCode === 200) {
984
- res.writeHead(200, fallbackRes.headers);
985
- fallbackRes.pipe(res);
986
- } else {
987
- fallbackRes.resume();
988
- tryNextExtension(index + 1);
989
- }
990
- }
991
- );
992
- fallbackReq.on("error", () => tryNextExtension(index + 1));
993
- fallbackReq.end();
994
- };
995
- tryNextExtension(0);
987
+ }
988
+ res.writeHead(proxyRes.statusCode || 404, proxyRes.headers);
989
+ proxyRes.pipe(res);
996
990
  }
997
991
  );
998
992
  proxyReq.on("error", (err) => {
@@ -1008,8 +1002,7 @@ async function devCommand(options) {
1008
1002
  proxyReq.end();
1009
1003
  }
1010
1004
  };
1011
- const shouldTryExtensions = !url.includes(".") && !url.endsWith("/");
1012
- proxyRequest(url, res, shouldTryExtensions);
1005
+ proxyRequest(url, res);
1013
1006
  });
1014
1007
  const cliPort = port;
1015
1008
  await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));