diff --git a/server/index.ts b/server/index.ts index a98c464e4854..d7b5ae8af9e2 100644 --- a/server/index.ts +++ b/server/index.ts @@ -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"; @@ -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 {