Skip to content

Commit

Permalink
fix /npm/ code elision
Browse files Browse the repository at this point in the history
add .gcloudignore for local deployment
add jwt decoding code
  • Loading branch information
mhuebert committed Nov 7, 2024
1 parent 729f13c commit 2507bae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
__pycache__/
# Ignored by the build system
/setup.cfg
key.json
key.json
**/__pycache__
**/.venv
private-website-cache
28 changes: 27 additions & 1 deletion src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,35 @@ const serveHtmlWithFallbacks = async (res, parentDomain, subDomain, filePaths) =
res.status(404).send('File not found');
};

const decodeJwt = (token) => {
if (!token) return null;

// Split the token into parts
const parts = token.split('.');
if (parts.length !== 3) return null;

try {
// Decode the payload (second part)
const payload = Buffer.from(parts[1], 'base64').toString();
return JSON.parse(payload);
} catch (e) {
console.error('Error decoding JWT:', e);
return null;
}
};

const logIapInfo = (req) => {
const jwt = req.headers['x-goog-iap-jwt-assertion'];
console.log('Decoded JWT:', decodeJwt(jwt));
};

const handleRequest = async (parentDomain, subDomain, filePath, req, res) => {

if (req.url.startsWith("/npm/")) {
// ... existing npm redirect code ...
// workaround for a Quarto issue, https://github.com/quarto-dev/quarto-cli/blob/bee87fb00ac2bad4edcecd1671a029b561c20b69/src/core/jupyter/widgets.ts#L120
// the embed-amd.js script tag should have a `data-jupyter-widgets-cdn-only` attribute (https://www.evanmarie.com/content/files/notebooks/ipywidgets.html)
res.redirect(302, `https://cdn.jsdelivr.net${req.url}`);
return;
}

const fileExtension = getExtension(filePath);
Expand Down

0 comments on commit 2507bae

Please sign in to comment.