@flight-framework/cli 0.4.6 → 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 +26 -34
- package/dist/bin.js.map +1 -1
- package/dist/index.js +26 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -946,7 +946,7 @@ async function devCommand(options) {
|
|
|
946
946
|
}
|
|
947
947
|
return;
|
|
948
948
|
}
|
|
949
|
-
const proxyRequest = (targetUrl, originalRes
|
|
949
|
+
const proxyRequest = async (targetUrl, originalRes) => {
|
|
950
950
|
const proxyReq = http.request(
|
|
951
951
|
{
|
|
952
952
|
hostname: "localhost",
|
|
@@ -955,45 +955,38 @@ async function devCommand(options) {
|
|
|
955
955
|
method: req.method,
|
|
956
956
|
headers: req.headers
|
|
957
957
|
},
|
|
958
|
-
(proxyRes) => {
|
|
959
|
-
if (proxyRes.statusCode !== 404
|
|
958
|
+
async (proxyRes) => {
|
|
959
|
+
if (proxyRes.statusCode !== 404) {
|
|
960
960
|
res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
|
|
961
961
|
proxyRes.pipe(res);
|
|
962
962
|
return;
|
|
963
963
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
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) {
|
|
968
983
|
res.writeHead(404, proxyRes.headers);
|
|
969
984
|
res.end("Not Found");
|
|
970
985
|
return;
|
|
971
986
|
}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
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);
|
|
987
|
+
}
|
|
988
|
+
res.writeHead(proxyRes.statusCode || 404, proxyRes.headers);
|
|
989
|
+
proxyRes.pipe(res);
|
|
997
990
|
}
|
|
998
991
|
);
|
|
999
992
|
proxyReq.on("error", (err) => {
|
|
@@ -1009,8 +1002,7 @@ async function devCommand(options) {
|
|
|
1009
1002
|
proxyReq.end();
|
|
1010
1003
|
}
|
|
1011
1004
|
};
|
|
1012
|
-
|
|
1013
|
-
proxyRequest(url, res, shouldTryExtensions);
|
|
1005
|
+
proxyRequest(url, res);
|
|
1014
1006
|
});
|
|
1015
1007
|
const cliPort = port;
|
|
1016
1008
|
await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));
|