From ecc6a4833f68eaf78bd5d619ff7c54b952c96b15 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 29 Mar 2022 07:35:03 -0400 Subject: [PATCH] Implement the Astro.request RFC (#2913) * Implement the Astro.request RFC * Disable console warnings eslint * Use our logger * Adds a changeset * Fix tests that depend on params, canonicalURL, URL Co-authored-by: Fred K. Schott --- .changeset/perfect-dogs-turn.md | 5 ++ .../src/layouts/post.astro | 2 +- .../src/pages/about.astro | 2 +- .../src/pages/index.astro | 2 +- .../src/pages/posts/[...page].astro | 6 +-- examples/docs/src/layouts/MainLayout.astro | 2 +- examples/ssr/src/pages/products/[id].astro | 2 +- packages/astro/src/@types/astro.ts | 9 ++-- packages/astro/src/core/app/index.ts | 12 ++--- packages/astro/src/core/build/generate.ts | 5 +- packages/astro/src/core/endpoint/index.ts | 7 ++- packages/astro/src/core/render/core.ts | 9 ++-- packages/astro/src/core/render/dev/index.ts | 11 ++-- packages/astro/src/core/render/request.ts | 50 ------------------- packages/astro/src/core/render/result.ts | 13 ++--- packages/astro/src/core/request.ts | 44 ++++++++++++++++ packages/astro/src/runtime/server/index.ts | 3 +- .../src/vite-plugin-astro-server/index.ts | 22 ++++++-- .../astro/src/vite-plugin-build-html/index.ts | 8 ++- packages/astro/test/astro-global.test.js | 2 +- .../src/pages/[...calledTwiceTest].astro | 2 +- .../src/pages/blog/[year]/[slug].astro | 4 +- .../src/pages/pizza/[...pizza].astro | 4 +- .../src/pages/pizza/[cheese]-[topping].astro | 4 +- .../astro-global/src/components/Child.astro | 4 +- .../src/components/NestedChild.astro | 2 +- .../astro-global/src/layouts/post.astro | 2 +- .../astro-global/src/pages/index.astro | 4 +- .../astro-global/src/pages/posts/[page].astro | 2 +- .../astro-pagination/src/pages/index.astro | 4 +- .../src/pages/posts/[slug]/[page].astro | 2 +- .../pages/posts/named-root-page/[page].astro | 2 +- .../posts/optional-root-page/[...page].astro | 2 +- .../fixtures/ssr-dynamic/src/pages/[id].astro | 2 +- 34 files changed, 135 insertions(+), 121 deletions(-) create mode 100644 .changeset/perfect-dogs-turn.md delete mode 100644 packages/astro/src/core/render/request.ts create mode 100644 packages/astro/src/core/request.ts diff --git a/.changeset/perfect-dogs-turn.md b/.changeset/perfect-dogs-turn.md new file mode 100644 index 000000000..61517d560 --- /dev/null +++ b/.changeset/perfect-dogs-turn.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Implements the Astro.request RFC diff --git a/examples/blog-multiple-authors/src/layouts/post.astro b/examples/blog-multiple-authors/src/layouts/post.astro index fd8fcefa6..bbfc7b335 100644 --- a/examples/blog-multiple-authors/src/layouts/post.astro +++ b/examples/blog-multiple-authors/src/layouts/post.astro @@ -4,7 +4,7 @@ import Nav from '../components/Nav.astro'; import authorData from '../data/authors.json'; const { content } = Astro.props; -let canonicalURL = Astro.request.canonicalURL; +let canonicalURL = Astro.canonicalURL; --- diff --git a/examples/blog-multiple-authors/src/pages/about.astro b/examples/blog-multiple-authors/src/pages/about.astro index ad101368b..f1097a6f4 100644 --- a/examples/blog-multiple-authors/src/pages/about.astro +++ b/examples/blog-multiple-authors/src/pages/about.astro @@ -4,7 +4,7 @@ import Nav from '../components/Nav.astro'; let title = 'About'; let description = 'About page of an example blog on Astro'; -let canonicalURL = Astro.request.canonicalURL; +let canonicalURL = Astro.canonicalURL; --- diff --git a/examples/blog-multiple-authors/src/pages/index.astro b/examples/blog-multiple-authors/src/pages/index.astro index 518424b99..0c8d701ea 100644 --- a/examples/blog-multiple-authors/src/pages/index.astro +++ b/examples/blog-multiple-authors/src/pages/index.astro @@ -12,7 +12,7 @@ import authorData from '../data/authors.json'; // All variables are available to use in the HTML template below. let title = 'Don’s Blog'; let description = 'An example blog on Astro'; -let canonicalURL = Astro.request.canonicalURL; +let canonicalURL = Astro.canonicalURL; // Data Fetching: List all Markdown posts in the repo. let allPosts = await Astro.glob('./post/*.md'); diff --git a/examples/blog-multiple-authors/src/pages/posts/[...page].astro b/examples/blog-multiple-authors/src/pages/posts/[...page].astro index da9b06fc5..7711a940c 100644 --- a/examples/blog-multiple-authors/src/pages/posts/[...page].astro +++ b/examples/blog-multiple-authors/src/pages/posts/[...page].astro @@ -28,9 +28,9 @@ export async function getStaticPaths({ paginate, rss }) { } // page -let title = 'Don’s Blog'; -let description = 'An example blog on Astro'; -let canonicalURL = Astro.request.canonicalURL; +const title = 'Don’s Blog'; +const description = 'An example blog on Astro'; +const { canonicalURL } = Astro; const { page } = Astro.props; --- diff --git a/examples/docs/src/layouts/MainLayout.astro b/examples/docs/src/layouts/MainLayout.astro index 92e0bcf44..8c46278fe 100644 --- a/examples/docs/src/layouts/MainLayout.astro +++ b/examples/docs/src/layouts/MainLayout.astro @@ -17,7 +17,7 @@ const githubEditUrl = CONFIG.GITHUB_EDIT_URL && CONFIG.GITHUB_EDIT_URL + current - + {content.title ? `${content.title} 🚀 ${CONFIG.SITE.title}` : CONFIG.SITE.title}