Spaces:
Running
Running
fix: inject Jupyter token header to skip JupyterLab's own login screen
Browse filesProxy requests to JupyterLab now include Authorization: token <JUPYTER_TOKEN>
so Jupyter recognises the session and doesn't show its password prompt.
Our /login gate handles auth — no need for a second Jupyter login.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- health-server.js +4 -0
health-server.js
CHANGED
|
@@ -482,6 +482,7 @@ function proxyHTTP(req, res, targetHost, targetPort, options = {}) {
|
|
| 482 |
"x-forwarded-host": req.headers.host,
|
| 483 |
"x-forwarded-proto": "https",
|
| 484 |
"x-forwarded-prefix": options.publicPrefix || "",
|
|
|
|
| 485 |
};
|
| 486 |
|
| 487 |
const canReplayRequest = req.method === "GET" || req.method === "HEAD";
|
|
@@ -630,12 +631,15 @@ const server = http.createServer(async (req, res) => {
|
|
| 630 |
return res.end(renderPrivateRedirect(HF_SPACE_URL));
|
| 631 |
}
|
| 632 |
if (!requireAuth(req, res)) return;
|
|
|
|
|
|
|
| 633 |
return proxyHTTP(req, res, JUPYTER_HOST, JUPYTER_PORT, {
|
| 634 |
publicPrefix: JUPYTER_BASE,
|
| 635 |
// Jupyter is started with --ServerApp.base_url=/terminal/, so keep the
|
| 636 |
// /terminal prefix when proxying. Stripping it breaks static/theme URLs.
|
| 637 |
stripPrefix: "",
|
| 638 |
retryWithoutPrefixOn404: false,
|
|
|
|
| 639 |
});
|
| 640 |
}
|
| 641 |
|
|
|
|
| 482 |
"x-forwarded-host": req.headers.host,
|
| 483 |
"x-forwarded-proto": "https",
|
| 484 |
"x-forwarded-prefix": options.publicPrefix || "",
|
| 485 |
+
...(options.extraHeaders || {}),
|
| 486 |
};
|
| 487 |
|
| 488 |
const canReplayRequest = req.method === "GET" || req.method === "HEAD";
|
|
|
|
| 631 |
return res.end(renderPrivateRedirect(HF_SPACE_URL));
|
| 632 |
}
|
| 633 |
if (!requireAuth(req, res)) return;
|
| 634 |
+
// Inject the Jupyter token so JupyterLab skips its own login screen.
|
| 635 |
+
const jToken = (process.env.JUPYTER_TOKEN || "").trim();
|
| 636 |
return proxyHTTP(req, res, JUPYTER_HOST, JUPYTER_PORT, {
|
| 637 |
publicPrefix: JUPYTER_BASE,
|
| 638 |
// Jupyter is started with --ServerApp.base_url=/terminal/, so keep the
|
| 639 |
// /terminal prefix when proxying. Stripping it breaks static/theme URLs.
|
| 640 |
stripPrefix: "",
|
| 641 |
retryWithoutPrefixOn404: false,
|
| 642 |
+
extraHeaders: jToken ? { authorization: `token ${jToken}` } : {},
|
| 643 |
});
|
| 644 |
}
|
| 645 |
|