@flight-framework/cli 0.4.4 → 0.4.5

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Flight Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/bin.js CHANGED
@@ -945,25 +945,71 @@ async function devCommand(options) {
945
945
  }
946
946
  return;
947
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);
948
+ const proxyRequest = (targetUrl, originalRes, attemptExtensions = false) => {
949
+ const proxyReq = http.request(
950
+ {
951
+ hostname: "localhost",
952
+ port: transformPort,
953
+ path: targetUrl,
954
+ method: req.method,
955
+ headers: req.headers
956
+ },
957
+ (proxyRes) => {
958
+ if (proxyRes.statusCode !== 404 || !attemptExtensions) {
959
+ res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
960
+ proxyRes.pipe(res);
961
+ return;
962
+ }
963
+ proxyRes.resume();
964
+ const commonExtensions = [".mjs", ".js", ".ts", ".tsx", ".jsx", "/index.js"];
965
+ const tryNextExtension = (index) => {
966
+ if (index >= commonExtensions.length) {
967
+ res.writeHead(404, proxyRes.headers);
968
+ res.end("Not Found");
969
+ return;
970
+ }
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);
996
+ }
997
+ );
998
+ proxyReq.on("error", (err) => {
999
+ console.error("[CLI Proxy Error]", err.message);
1000
+ if (!res.headersSent) {
1001
+ res.writeHead(502, { "Content-Type": "text/plain" });
1002
+ res.end("FlightPack transform server unavailable");
1003
+ }
1004
+ });
1005
+ if (req.method !== "GET" && req.method !== "HEAD") {
1006
+ req.pipe(proxyReq);
1007
+ } else {
1008
+ proxyReq.end();
959
1009
  }
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);
1010
+ };
1011
+ const shouldTryExtensions = !url.includes(".") && !url.endsWith("/");
1012
+ proxyRequest(url, res, shouldTryExtensions);
967
1013
  });
968
1014
  const cliPort = port;
969
1015
  await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));