- Add test-results/.last-run.json to .gitignore - Remove from git tracking - Update Makefile dev target port (8080, not 8081) - Add debug logging to dev-server.mjs API proxy
This commit is contained in:
+13
-2
@@ -121,12 +121,14 @@ app.use("/map", (req, res) => {
|
||||
// Two transports: (1) direct with `--noproxy '*'` — fast path when the
|
||||
// upstream is publicly reachable; (2) through the system HTTPS_PROXY
|
||||
// (e.g. a local gost VPN tunnel) — required when the direct IP hits a
|
||||
// WAF throttle (403 deny page). Try direct first; on 403/4xx/5xx or
|
||||
// WAF throttle (403 deny page). Try direct first; on 4xx/5xx or
|
||||
// network error, retry through the proxy. Each transport keeps its own
|
||||
// cookie jar because the WAF cookie is bound to the edge node that
|
||||
// minted it.
|
||||
app.use(["/api", "/flights"], (req, res) => {
|
||||
console.log(`API proxy called for: ${req.originalUrl}`);
|
||||
const targetUrl = `${API_TARGET}${req.originalUrl}`;
|
||||
console.log(`targetUrl: ${targetUrl}`);
|
||||
|
||||
const buildArgs = (noproxy) => [
|
||||
"-s",
|
||||
@@ -154,7 +156,9 @@ app.use(["/api", "/flights"], (req, res) => {
|
||||
});
|
||||
|
||||
function execCurlWithFallback(buildArgs, extraArgs, res) {
|
||||
console.log(`execCurlWithFallback called`);
|
||||
runCurl([...extraArgs, ...buildArgs(true)], (direct) => {
|
||||
console.log(`execCurlWithFallback: direct result, isSuccessful=${isSuccessfulUpstream(direct)}`);
|
||||
if (isSuccessfulUpstream(direct)) {
|
||||
respondWithCurlResult(direct, res);
|
||||
return;
|
||||
@@ -168,7 +172,10 @@ function execCurlWithFallback(buildArgs, extraArgs, res) {
|
||||
}
|
||||
|
||||
function runCurl(args, cb) {
|
||||
execFile("/usr/bin/curl", args, { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }, (err, stdout) => {
|
||||
console.log(`runCurl: args=${JSON.stringify(args).substring(0, 200)}...`);
|
||||
execFile("/usr/bin/curl", args, { maxBuffer: 10 * 1024 * 1024, timeout: 30000 }, (err, stdout, stderr) => {
|
||||
console.log(`runCurl callback: err=${!!err}, stdout length=${stdout ? stdout.length : 0}, stderr length=${stderr ? stderr.length : 0}`);
|
||||
console.log(`runCurl stdout preview: ${stdout ? stdout.substring(0, 200) : 'null'}`);
|
||||
cb({ err, stdout: stdout ?? "" });
|
||||
});
|
||||
}
|
||||
@@ -182,6 +189,7 @@ function isSuccessfulUpstream({ err, stdout }) {
|
||||
}
|
||||
|
||||
function respondWithCurlResult({ err, stdout }, res) {
|
||||
console.log(`respondWithCurlResult: err=${!!err}, stdout length=${stdout ? stdout.length : 0}`);
|
||||
if (err) {
|
||||
res.status(502).json({ error: err.message });
|
||||
return;
|
||||
@@ -199,6 +207,9 @@ function respondWithCurlResult({ err, stdout }, res) {
|
||||
|
||||
const isJson = body.trimStart().startsWith("{") || body.trimStart().startsWith("[");
|
||||
|
||||
console.log(`isJson=${isJson}, status=${status}, body length=${body.length}`);
|
||||
console.log(`body preview: ${body.substring(0, 200)}`);
|
||||
|
||||
res.status(status);
|
||||
res.set("Content-Type", isJson ? "application/json" : "text/html");
|
||||
res.set("Access-Control-Allow-Origin", "*");
|
||||
|
||||
Reference in New Issue
Block a user