Skip to content

Commit 2b5fb1b

Browse files
authored
fix(rari): fix blog and add .env support (#12268)
1 parent bb3f8ec commit 2b5fb1b

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Diff for: server/cli.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
import { concurrently } from "concurrently";
33
import { rariBin } from "@mdn/rari";
44
import { filename } from "./filename.js";
5+
import { config } from "dotenv";
6+
import path from "node:path";
7+
import { cwd } from "node:process";
8+
9+
config({
10+
path: path.join(cwd(), process.env.ENV_FILE || ".env"),
11+
});
512

613
const { commands, result } = concurrently(
714
[
@@ -17,6 +24,9 @@ const { commands, result } = concurrently(
1724
command: `${rariBin} serve -vv`,
1825
name: "rari",
1926
prefixColor: "blue",
27+
env: {
28+
...process.env,
29+
},
2030
},
2131
],
2232
{

Diff for: server/index.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ if (CURRICULUM_ROOT) {
346346
data = await findCurriculumPageBySlug(slug);
347347
} else {
348348
try {
349-
data = await fetch_from_rari(req.path);
349+
data = await fetch_from_rari(req.path.replace(/index\.json$/, ""));
350350
} catch (error) {
351351
return res.status(500).json(JSON.stringify(error.toString()));
352352
}
@@ -374,7 +374,9 @@ if (BLOG_ROOT) {
374374
return res.json({ hyData: { posts } });
375375
} else {
376376
try {
377-
const index = await fetch_from_rari(req.path);
377+
const index = await fetch_from_rari(
378+
req.path.replace(/index\.json$/, "")
379+
);
378380
return res.json(index);
379381
} catch (error) {
380382
return res.status(500).json(JSON.stringify(error.toString()));
@@ -404,7 +406,9 @@ if (BLOG_ROOT) {
404406
return res.json(data);
405407
} else {
406408
try {
407-
const index = await fetch_from_rari(req.path);
409+
const index = await fetch_from_rari(
410+
req.path.replace(/index\.json$/, "")
411+
);
408412
return res.json(index);
409413
} catch (error) {
410414
return res.status(500).json(JSON.stringify(error.toString()));
@@ -446,7 +450,7 @@ if (contentProxy) {
446450
}
447451
});
448452
app.get("/[^/]+/docs/*/index.json", async (req, res) => {
449-
const url = decodeURI(req.path.replace(/\/index.json$/, ""));
453+
const url = decodeURI(req.path.replace(/\/index\.json$/, ""));
450454
try {
451455
const doc = await buildDocumentFromURL(url);
452456
if (!doc) {
@@ -513,7 +517,9 @@ if (RARI) {
513517
],
514518
async (req, res) => {
515519
try {
516-
const index = await fetch_from_rari(req.path);
520+
const index = await fetch_from_rari(
521+
req.path.replace(/index\.json$/, "")
522+
);
517523
if (req.path.endsWith(".json")) {
518524
return res.json(index);
519525
}

0 commit comments

Comments
 (0)