1- declare const htmlTemplate : string ;
2- // @ts -expect-error cloudflare converts this to a string using esbuild
1+ declare const htmlTemplate : string ; // @ts -expect-error cloudflare converts this to a string using esbuild
32import htmlTemplate from "../../public/template.html" ;
3+ declare const notFoundEn : string ; // @ts -expect-error cloudflare converts this to a string using esbuild
4+ import notFoundEn from "../../public/404.html" ;
45
56import { fsConfig } from "@dzcode.io/utils/dist/config" ;
67import { Environment , environments } from "@dzcode.io/utils/dist/config/environment" ;
@@ -24,11 +25,14 @@ export const onRequest: PagesFunction<Env> = async (context) => {
2425
2526 const pathName = new URL ( context . request . url ) . pathname ;
2627
27- const slug = pathName . split ( "/" ) . pop ( ) ;
28- const projectId = slug ?. split ( "-" ) . pop ( ) ;
28+ const projectIdRegex = / p r o j e c t s \/ ( . * ) - ( . \d ) + / ;
29+ const projectId = pathName ?. match ( projectIdRegex ) ?. [ 2 ] ;
2930
30- // @TODO -ZM: render 404 page
31- if ( ! projectId ) return new Response ( "Not found" , { status : 404 } ) ;
31+ if ( ! projectId )
32+ return new Response ( notFoundEn , {
33+ headers : { "content-type" : "text/html; charset=utf-8" } ,
34+ status : 404 ,
35+ } ) ;
3236
3337 // @TODO -ZM: get language from request url
3438 const language = "en" ;
@@ -45,9 +49,5 @@ export const onRequest: PagesFunction<Env> = async (context) => {
4549 . replace ( / { { template-t i t l e } } / g, pageTitle )
4650 . replace ( / { { template-d e s c r i p t i o n } } / g, localize ( "projects-description" ) ) ;
4751
48- return new Response ( newData , {
49- headers : {
50- "content-type" : "text/html; charset=utf-8" ,
51- } ,
52- } ) ;
52+ return new Response ( newData , { headers : { "content-type" : "text/html; charset=utf-8" } } ) ;
5353} ;
0 commit comments