Skip to content

Commit

Permalink
fix(rari): fix blog and add .env support (#12268)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo authored Dec 6, 2024
1 parent bb3f8ec commit 2b5fb1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
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 @@ -346,7 +346,7 @@ if (CURRICULUM_ROOT) {
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 @@ if (BLOG_ROOT) {
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 @@ if (BLOG_ROOT) {
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 @@ if (contentProxy) {
}
});
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 @@ if (RARI) {
],
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

0 comments on commit 2b5fb1b

Please sign in to comment.