Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rari): fix blog and add .env support #12268

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
import { concurrently } from "concurrently";
import { rariBin } from "@mdn/rari";
import { filename } from "./filename.js";
import { config } from "dotenv";
import path from "node:path";
import { cwd } from "node:process";

config({
path: path.join(cwd(), process.env.ENV_FILE || ".env"),
});

const { commands, result } = concurrently(
[
Expand All @@ -17,6 +24,9 @@ const { commands, result } = concurrently(
command: `${rariBin} serve -vv`,
name: "rari",
prefixColor: "blue",
env: {
...process.env,
},
},
],
{
Expand Down
16 changes: 11 additions & 5 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
const redirectURL = Redirect.resolve(url);
if (redirectURL !== url) {
// This was and is broken for redirects with anchors...
return res.redirect(301, redirectURL + suffix);

Check warning

Code scanning / CodeQL

Server-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.
}
return await send404(res);
}
Expand Down Expand Up @@ -346,7 +346,7 @@
data = await findCurriculumPageBySlug(slug);
} else {
try {
data = await fetch_from_rari(req.path);
data = await fetch_from_rari(req.path.replace(/index\.json$/, ""));
} catch (error) {
return res.status(500).json(JSON.stringify(error.toString()));
}
Expand Down Expand Up @@ -374,7 +374,9 @@
return res.json({ hyData: { posts } });
} else {
try {
const index = await fetch_from_rari(req.path);
const index = await fetch_from_rari(
req.path.replace(/index\.json$/, "")
);
return res.json(index);
} catch (error) {
return res.status(500).json(JSON.stringify(error.toString()));
Expand Down Expand Up @@ -404,7 +406,9 @@
return res.json(data);
} else {
try {
const index = await fetch_from_rari(req.path);
const index = await fetch_from_rari(
req.path.replace(/index\.json$/, "")
);
return res.json(index);
} catch (error) {
return res.status(500).json(JSON.stringify(error.toString()));
Expand Down Expand Up @@ -446,7 +450,7 @@
}
});
app.get("/[^/]+/docs/*/index.json", async (req, res) => {
const url = decodeURI(req.path.replace(/\/index.json$/, ""));
const url = decodeURI(req.path.replace(/\/index\.json$/, ""));
try {
const doc = await buildDocumentFromURL(url);
if (!doc) {
Expand Down Expand Up @@ -513,7 +517,9 @@
],
async (req, res) => {
try {
const index = await fetch_from_rari(req.path);
const index = await fetch_from_rari(
req.path.replace(/index\.json$/, "")
);
if (req.path.endsWith(".json")) {
return res.json(index);
}
Expand Down
Loading