Skip to content

Commit 609f84b

Browse files
authored
Merge pull request #603 from dzcode-io/cloudflare-redirect
fix: Cloudflare 404 redirect
2 parents 97ed8a4 + 60b89a0 commit 609f84b

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"build:watch": "lerna run build:alone:watch [email protected]/web --include-dependencies --parallel",
6565
"bundle": "npm run build && npm run bundle:alone",
6666
"bundle:alone": "cross-env NODE_ENV=production rsbuild build",
67+
"bundle:preview": "rsbuild preview",
6768
"bundle:doctor": "RSDOCTOR=true rsbuild build",
6869
"clean": "lerna run clean:alone [email protected]/web --include-dependencies --stream",
6970
"clean:alone": "rimraf dist coverage bundle node_modules/.cache && rimraf ./cloudflare/public",

web/src/_build/gen-multiple-htmls.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// for dev, run:
22
// npm run clean && npm run bundle && npm run generate:htmls
3-
// npm run rsbuild preview
3+
// npm run bundle:preview
44

55
import { join } from "path";
66
import { readFileSync, writeFileSync, mkdirSync } from "fs";
@@ -24,13 +24,14 @@ const SKIP_ROOT_HTML = process.env.SKIP_ROOT_HTML === "true";
2424
console.log(`generating ${allPages.length} html files ...`);
2525

2626
allPages.forEach((pageInfo) => {
27-
const pathName = pageInfo.uri;
28-
const outputHtmlDir = join(distFolder, pathName);
29-
const outputHtmlPath = join(outputHtmlDir, "index.html");
30-
if (SKIP_ROOT_HTML && outputHtmlPath === indexHtmlPath) {
31-
console.log(`skipping root html: ${outputHtmlPath}`);
27+
let pathName = pageInfo.uri.replace(/\/$/, "");
28+
pathName = `${pathName || "index"}.html`;
29+
if (SKIP_ROOT_HTML && pathName === "index.html") {
30+
console.log(`skipping root html`);
3231
return;
3332
}
33+
const outputHtmlPath = join(distFolder, pathName);
34+
const outputHtmlParentDir = join(outputHtmlPath, "..");
3435

3536
let newHtml = indexHtml;
3637
newHtml = newHtml.replace(
@@ -58,7 +59,7 @@ allPages.forEach((pageInfo) => {
5859
newHtml = newHtml.replace(/{{ogImage}}/g, pageInfo.ogImage);
5960
newHtml = newHtml.replace(/{{sentryOrigin}}/g, `https://${SENTRY_ORIGIN}`);
6061

61-
mkdirSync(outputHtmlDir, { recursive: true });
62+
mkdirSync(outputHtmlParentDir, { recursive: true });
6263
writeFileSync(outputHtmlPath, newHtml);
6364

6465
console.log(outputHtmlPath, "✅");

web/src/_build/gen-robots-txt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// for dev, run:
22
// npm run clean && npm run bundle && npm run generate:robots-txt
3-
// npm run rsbuild preview
3+
// npm run bundle:preview
44

55
import { join } from "path";
66
import { writeFileSync } from "fs";

web/src/_build/pages/static-pages.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ const staticURLs: PageInfoWithLocalKeys[] = [
4848
"https://images.unsplash.com/photo-1526663089957-f2aa2776f572?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
4949
keywords: "faq, open-source, algeria, dzcode",
5050
},
51+
{
52+
uri: "/404",
53+
title: "notfound-title",
54+
description: "notfound-description",
55+
ogImage:
56+
"https://images.unsplash.com/photo-1510133768164-a8f7e4d4e3dc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=750&q=80&auto=format&fit=crop&w=1200&h=627&q=80",
57+
keywords: "faq, open-source, algeria, dzcode",
58+
},
5159
];
5260

5361
export const staticPages: PageInfo[] = staticURLs.reduce<PageInfo[]>(

0 commit comments

Comments
 (0)