@flight-framework/cli 0.4.4 → 0.4.6
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/LICENSE +21 -0
- package/dist/bin.js +66 -19
- package/dist/bin.js.map +1 -1
- package/dist/index.js +66 -19
- package/dist/index.js.map +1 -1
- package/package.json +53 -53
package/dist/index.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
|
-
|
|
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,25 +946,71 @@ async function devCommand(options) {
|
|
|
945
946
|
}
|
|
946
947
|
return;
|
|
947
948
|
}
|
|
948
|
-
const
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
949
|
+
const proxyRequest = (targetUrl, originalRes, attemptExtensions = false) => {
|
|
950
|
+
const proxyReq = http.request(
|
|
951
|
+
{
|
|
952
|
+
hostname: "localhost",
|
|
953
|
+
port: transformPort,
|
|
954
|
+
path: targetUrl,
|
|
955
|
+
method: req.method,
|
|
956
|
+
headers: req.headers
|
|
957
|
+
},
|
|
958
|
+
(proxyRes) => {
|
|
959
|
+
if (proxyRes.statusCode !== 404 || !attemptExtensions) {
|
|
960
|
+
res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
|
|
961
|
+
proxyRes.pipe(res);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
proxyRes.resume();
|
|
965
|
+
const commonExtensions = [".mjs", ".js", ".ts", ".tsx", ".jsx", "/index.js"];
|
|
966
|
+
const tryNextExtension = (index) => {
|
|
967
|
+
if (index >= commonExtensions.length) {
|
|
968
|
+
res.writeHead(404, proxyRes.headers);
|
|
969
|
+
res.end("Not Found");
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const ext = commonExtensions[index];
|
|
973
|
+
const fallbackUrl = targetUrl + ext;
|
|
974
|
+
const fallbackReq = http.request(
|
|
975
|
+
{
|
|
976
|
+
hostname: "localhost",
|
|
977
|
+
port: transformPort,
|
|
978
|
+
path: fallbackUrl,
|
|
979
|
+
method: "GET",
|
|
980
|
+
// Always GET for fallbacks
|
|
981
|
+
headers: req.headers
|
|
982
|
+
},
|
|
983
|
+
(fallbackRes) => {
|
|
984
|
+
if (fallbackRes.statusCode === 200) {
|
|
985
|
+
res.writeHead(200, fallbackRes.headers);
|
|
986
|
+
fallbackRes.pipe(res);
|
|
987
|
+
} else {
|
|
988
|
+
fallbackRes.resume();
|
|
989
|
+
tryNextExtension(index + 1);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
);
|
|
993
|
+
fallbackReq.on("error", () => tryNextExtension(index + 1));
|
|
994
|
+
fallbackReq.end();
|
|
995
|
+
};
|
|
996
|
+
tryNextExtension(0);
|
|
997
|
+
}
|
|
998
|
+
);
|
|
999
|
+
proxyReq.on("error", (err) => {
|
|
1000
|
+
console.error("[CLI Proxy Error]", err.message);
|
|
1001
|
+
if (!res.headersSent) {
|
|
1002
|
+
res.writeHead(502, { "Content-Type": "text/plain" });
|
|
1003
|
+
res.end("FlightPack transform server unavailable");
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
1007
|
+
req.pipe(proxyReq);
|
|
1008
|
+
} else {
|
|
1009
|
+
proxyReq.end();
|
|
959
1010
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
res.writeHead(502, { "Content-Type": "text/plain" });
|
|
964
|
-
res.end("FlightPack transform server unavailable");
|
|
965
|
-
});
|
|
966
|
-
req.pipe(proxyReq);
|
|
1011
|
+
};
|
|
1012
|
+
const shouldTryExtensions = !url.includes(".") && !url.endsWith("/");
|
|
1013
|
+
proxyRequest(url, res, shouldTryExtensions);
|
|
967
1014
|
});
|
|
968
1015
|
const cliPort = port;
|
|
969
1016
|
await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));
|