From 8dd2c5ea4a02ef197bb4cf1dfda56885ca26bc63 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Wed, 27 Apr 2022 12:46:08 -0500 Subject: [PATCH] Add support for benchmark urls --- .../app/{[slug].astro => [...slug].astro} | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) rename src/pages/app/{[slug].astro => [...slug].astro} (83%) diff --git a/src/pages/app/[slug].astro b/src/pages/app/[...slug].astro similarity index 83% rename from src/pages/app/[slug].astro rename to src/pages/app/[...slug].astro index 8d23855..d16af30 100644 --- a/src/pages/app/[slug].astro +++ b/src/pages/app/[...slug].astro @@ -34,13 +34,19 @@ const { } = Astro.params -const apiUrl = new URL( import.meta.env.PUBLIC_API_DOMAIN ) - // Parse the request url const requestUrl = new URL( Astro.request.url ) -// Use request path to get api url path -apiUrl.pathname = `/api${ requestUrl.pathname }.json` +// Get type and slug from the request path +// so that we don't have extra parts for +// urls like /:type/:slug/benchmarks +const [ , pathType, pathSlug ] = requestUrl.pathname.split('/') + +// Create an empty API URL +const apiUrl = new URL( import.meta.env.PUBLIC_API_DOMAIN ) + +// Use request path parts to set api url path +apiUrl.pathname = `/api/${ pathType }/${ pathSlug }.json` // Astro Request reference @@ -50,7 +56,7 @@ console.log('Astro.params', Astro.params ) console.log('apiUrl', apiUrl ) console.log('Astro.request.url', Astro.request.url ) console.log('Astro.site.pathname', Astro.site.pathname ) -console.log('Astro.request', Astro.request ) +// console.log('Astro.request', Astro.request ) const appEntry = await axios.get( apiUrl.toString() ) .then( response => { @@ -82,8 +88,6 @@ const lastUpdatedFriendly = null
{ JSON.stringify( appEntry ) } - -