Skip to content

Commit

Permalink
fix(dev-server): support contributor spotlight
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Jan 15, 2025
1 parent 175daec commit 65c1575
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
CURRICULUM_ROOT,
EXTERNAL_DEV_SERVER,
RARI,
CONTRIBUTOR_SPOTLIGHT_ROOT,
} from "../libs/env/index.js";
import { PLAYGROUND_UNSAFE_CSP_VALUE } from "../libs/play/index.js";

Expand Down Expand Up @@ -505,15 +506,48 @@ if (contentProxy) {
}

if (RARI) {
app.get(
"/:locale/community/spotlight/:name/:asset(.+(jpg|png))",
async (req, res) => {
const { name, asset } = req.params;
return send(
req,
path.resolve(
CONTRIBUTOR_SPOTLIGHT_ROOT,
sanitizeFilename(name),
sanitizeFilename(asset)
)
).pipe(res);
}
);
app.get(
[
"/en-US/about",
"/en-US/about/index.json",
"/en-US/community",
"/en-US/community/index.json",
"/en-US/community/*",
"/en-US/plus/docs/*",
"/en-US/observatory/docs/*",
],
async (req, res) => {
try {
const index = await fetch_from_rari(
req.path.replace(/\/index\.json$/, "")
);
if (req.path.endsWith(".json")) {
return res.json(index);
}
res.header("Content-Security-Policy", CSP_VALUE);
return res.send(renderHTML(index));
} catch (error) {
return res.status(500).json(JSON.stringify(error.toString()));
}
}
);
app.get(
[
"/:locale([a-z]{2}(?:(?:-[A-Z]{2})?))/",
"/:locale([a-z]{2}(?:(?:-[A-Z]{2})?))/index.json",
],
async (req, res) => {
try {
Expand Down

0 comments on commit 65c1575

Please sign in to comment.