mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-10 11:14:09 +02:00
Add 404 handling
This commit is contained in:
1
.astro/types.d.ts
vendored
1
.astro/types.d.ts
vendored
@@ -1,2 +1 @@
|
|||||||
/// <reference types="astro/client" />
|
/// <reference types="astro/client" />
|
||||||
/// <reference path="content.d.ts" />
|
|
@@ -3,8 +3,6 @@ import Icon from '../components/AstroIcon.astro';
|
|||||||
import BaseLayout from '../layouts/BaseLayout.astro';
|
import BaseLayout from '../layouts/BaseLayout.astro';
|
||||||
import { getRoadmapIds } from '../lib/roadmap';
|
import { getRoadmapIds } from '../lib/roadmap';
|
||||||
|
|
||||||
export const prerender = true;
|
|
||||||
|
|
||||||
const roadmapIds = await getRoadmapIds();
|
const roadmapIds = await getRoadmapIds();
|
||||||
const legacyRoadmapUrls = [...roadmapIds.map((id) => `/${id}/`), '/roadmaps/'];
|
const legacyRoadmapUrls = [...roadmapIds.map((id) => `/${id}/`), '/roadmaps/'];
|
||||||
---
|
---
|
||||||
|
@@ -10,7 +10,10 @@ export const prerender = false;
|
|||||||
const { topicId, roadmapId } = Astro.params;
|
const { topicId, roadmapId } = Astro.params;
|
||||||
|
|
||||||
if (!topicId || !roadmapId) {
|
if (!topicId || !roadmapId) {
|
||||||
return Astro.redirect('/404');
|
Astro.response.status = 404;
|
||||||
|
Astro.response.statusText = 'Not found';
|
||||||
|
|
||||||
|
return Astro.rewrite('/404');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle nested paths by joining the segments
|
// Handle nested paths by joining the segments
|
||||||
@@ -48,7 +51,10 @@ if (!fs.existsSync(contentPath)) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!fs.existsSync(indexFilePath)) {
|
if (!fs.existsSync(indexFilePath)) {
|
||||||
return Astro.redirect('/404');
|
Astro.response.status = 404;
|
||||||
|
Astro.response.statusText = 'Not found';
|
||||||
|
|
||||||
|
return Astro.rewrite('/404');
|
||||||
}
|
}
|
||||||
|
|
||||||
contentPath = indexFilePath;
|
contentPath = indexFilePath;
|
||||||
|
Reference in New Issue
Block a user