diff options
34 files changed, 135 insertions, 121 deletions
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; --- <html lang={content.lang || 'en'}> 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; --- <html lang="en"> 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 <html dir={content.dir ?? 'ltr'} lang={content.lang ?? 'en-us'} class="initial"> <head> <HeadCommon /> - <HeadSEO {content} canonicalURL={Astro.request.canonicalURL} /> + <HeadSEO {content} canonicalURL={Astro.canonicalURL} /> <title>{content.title ? `${content.title} 🚀 ${CONFIG.SITE.title}` : CONFIG.SITE.title}</title> <style> body { diff --git a/examples/ssr/src/pages/products/[id].astro b/examples/ssr/src/pages/products/[id].astro index 37fe7e0b4..317cea635 100644 --- a/examples/ssr/src/pages/products/[id].astro +++ b/examples/ssr/src/pages/products/[id].astro @@ -5,7 +5,7 @@ import AddToCart from '../../components/AddToCart.svelte'; import { getProduct } from '../../api'; import '../../styles/common.css'; -const id = Number(Astro.request.params.id); +const id = Number(Astro.params.id); const product = await getProduct(id); --- diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index d7d61253d..fca4aff80 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -4,7 +4,6 @@ import type * as vite from 'vite'; import { z } from 'zod'; import type { AstroConfigSchema } from '../core/config'; import type { AstroComponentFactory, Metadata } from '../runtime/server'; -import type { AstroRequest } from '../core/render/request'; export type { SSRManifest } from '../core/app/types'; export interface AstroBuiltinProps { @@ -51,10 +50,14 @@ export interface BuildConfig { * Docs: https://docs.astro.build/reference/api-reference/#astro-global */ export interface AstroGlobal extends AstroGlobalPartial { + /** get the current canonical URL */ + canonicalURL: URL; + /** get page params (dynamic pages only) */ + params: Params; /** set props for this astro component (along with default values) */ props: Record<string, number | string | any>; /** get information about this page */ - request: AstroRequest; + request: Request; /** see if slots are used */ slots: Record<string, true | undefined> & { has(slotName: string): boolean; render(slotName: string): Promise<string> }; } @@ -632,7 +635,7 @@ export interface EndpointOutput<Output extends Body = Body> { } export interface EndpointHandler { - [method: string]: (params: any, request: AstroRequest) => EndpointOutput | Response; + [method: string]: (params: any, request: Request) => EndpointOutput | Response; } export interface AstroRenderer { diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 404492398..df3c94a68 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -10,6 +10,7 @@ import { call as callEndpoint } from '../endpoint/index.js'; import { RouteCache } from '../render/route-cache.js'; import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from '../render/ssr-element.js'; import { prependForwardSlash } from '../path.js'; +import { createRequest } from '../request.js'; export class App { #manifest: Manifest; @@ -17,6 +18,7 @@ export class App { #routeDataToRouteInfo: Map<RouteData, RouteInfo>; #routeCache: RouteCache; #encoder = new TextEncoder(); + #logging = defaultLogOptions; constructor(manifest: Manifest) { this.#manifest = manifest; @@ -63,7 +65,7 @@ export class App { const result = await render({ legacyBuild: false, links, - logging: defaultLogOptions, + logging: this.#logging, markdownRender: manifest.markdown.render, mod, origin: url.origin, @@ -81,8 +83,7 @@ export class App { routeCache: this.#routeCache, site: this.#manifest.site, ssr: true, - method: info.routeData.type === 'endpoint' ? '' : 'GET', - headers: request.headers, + request, }); if (result.type === 'response') { @@ -100,15 +101,14 @@ export class App { }); } - async #callEndpoint(request: Request, routeData: RouteData, mod: ComponentInstance): Promise<Response> { + async #callEndpoint(request: Request, _routeData: RouteData, mod: ComponentInstance): Promise<Response> { const url = new URL(request.url); const handler = mod as unknown as EndpointHandler; const result = await callEndpoint(handler, { - headers: request.headers, logging: defaultLogOptions, - method: request.method, origin: url.origin, pathname: url.pathname, + request, routeCache: this.#routeCache, ssr: true, }); diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 84d9dd7e2..f18f7b2bb 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -17,6 +17,7 @@ import { getOutFile, getOutFolder } from './common.js'; import { eachPageData, getPageDataByComponent } from './internal.js'; import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types'; import { getTimeStat } from './util.js'; +import { createRequest } from '../request.js'; // Render is usually compute, which Node.js can't parallelize well. // In real world testing, dropping from 10->1 showed a notiable perf @@ -164,6 +165,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G } } + const url = new URL(origin + pathname); const options: RenderOptions = { legacyBuild: false, links, @@ -191,8 +193,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G const fullyRelativePath = relPath[0] === '.' ? relPath : './' + relPath; return fullyRelativePath; }, - method: 'GET', - headers: new Headers(), + request: createRequest({ url, headers: new Headers(), logging }), route: pageData.route, routeCache, site: astroConfig.buildOptions.site, diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index 745811354..fb525066c 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -2,9 +2,9 @@ import type { EndpointHandler } from '../../@types/astro'; import type { RenderOptions } from '../render/core'; import { renderEndpoint } from '../../runtime/server/index.js'; import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js'; -import { createRequest } from '../render/request.js'; -export type EndpointOptions = Pick<RenderOptions, 'logging' | 'headers' | 'method' | 'origin' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr'>; +export type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | + 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr'>; type EndpointCallResult = | { @@ -23,9 +23,8 @@ export async function call(mod: EndpointHandler, opts: EndpointOptions): Promise throw new Error(`[getStaticPath] route pattern matched, but no matching static path found. (${opts.pathname})`); } const [params] = paramsAndPropsResp; - const request = createRequest(opts.method, opts.pathname, opts.headers, opts.origin, opts.site, opts.ssr); - const response = await renderEndpoint(mod, request, params); + const response = await renderEndpoint(mod, opts.request, params); if (response instanceof Response) { return { diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index a1ea94f65..3cb109b76 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -1,6 +1,5 @@ import type { ComponentInstance, EndpointHandler, MarkdownRenderOptions, Params, Props, SSRLoadedRenderer, RouteData, SSRElement } from '../../@types/astro'; import type { LogOptions } from '../logger.js'; -import type { AstroRequest } from './request'; import { renderHead, renderPage } from '../../runtime/server/index.js'; import { getParams } from '../routing/index.js'; @@ -71,12 +70,11 @@ export interface RenderOptions { routeCache: RouteCache; site?: string; ssr: boolean; - method: string; - headers: Headers; + request: Request; } export async function render(opts: RenderOptions): Promise<{ type: 'html'; html: string } | { type: 'response'; response: Response }> { - const { headers, legacyBuild, links, logging, origin, markdownRender, method, mod, pathname, scripts, renderers, resolve, route, routeCache, site, ssr } = opts; + const { legacyBuild, links, logging, origin, markdownRender, mod, pathname, scripts, renderers, request, resolve, route, routeCache, site, ssr } = opts; const paramsAndPropsRes = await getParamsAndProps({ logging, @@ -107,11 +105,10 @@ export async function render(opts: RenderOptions): Promise<{ type: 'html'; html: pathname, resolve, renderers, + request, site, scripts, ssr, - method, - headers, }); let page = await renderPage(result, Component, pageProps, null); diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index af92aca85..b96a431ae 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -28,10 +28,8 @@ export interface SSROptions { routeCache: RouteCache; /** Vite instance */ viteServer: vite.ViteDevServer; - /** Method */ - method: string; - /** Headers */ - headers: Headers; + /** Request */ + request: Request; } export type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance]; @@ -64,7 +62,7 @@ export async function preload({ astroConfig, filePath, viteServer }: Pick<SSROpt /** use Vite to SSR */ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInstance, ssrOpts: SSROptions): Promise<RenderResponse> { - const { astroConfig, filePath, logging, mode, origin, pathname, method, headers, route, routeCache, viteServer } = ssrOpts; + const { astroConfig, filePath, logging, mode, origin, pathname, request, route, routeCache, viteServer } = ssrOpts; const legacy = astroConfig.buildOptions.legacyBuild; // Add hoisted script tags @@ -144,12 +142,11 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta } }, renderers, + request, route, routeCache, site: astroConfig.buildOptions.site, ssr: astroConfig.buildOptions.experimentalSsr, - method, - headers, }); if (route?.type === 'endpoint' || content.type === 'response') { diff --git a/packages/astro/src/core/render/request.ts b/packages/astro/src/core/render/request.ts deleted file mode 100644 index 5956c7867..000000000 --- a/packages/astro/src/core/render/request.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { Params } from '../../@types/astro'; -import { canonicalURL as utilCanonicalURL } from '../util.js'; - -type Site = string | undefined; - -export interface AstroRequest { - /** get the current page URL */ - url: URL; - - /** get the current canonical URL */ - canonicalURL: URL; - - /** get page params (dynamic pages only) */ - params: Params; - - headers: Headers; - - method: string; -} - -export type AstroRequestSSR = AstroRequest; - -export function createRequest(method: string, pathname: string, headers: Headers, origin: string, site: Site, ssr: boolean): AstroRequest { - const url = new URL('.' + pathname, new URL(origin)); - - const canonicalURL = utilCanonicalURL('.' + pathname, site ?? url.origin); - - const request: AstroRequest = { - url, - canonicalURL, - params: {}, - headers, - method, - }; - - if (!ssr) { - // Headers are only readable if using SSR-mode. If not, make it an empty headers - // object, so you can't do something bad. - request.headers = new Headers(); - - // Disallow using query params. - request.url = new URL(request.url); - - for (const [key] of request.url.searchParams) { - request.url.searchParams.delete(key); - } - } - - return request; -} diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 8b14c99bd..6f03d4806 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -3,7 +3,7 @@ import type { AstroGlobal, AstroGlobalPartial, MarkdownParser, MarkdownRenderOpt import { renderSlot } from '../../runtime/server/index.js'; import { LogOptions, warn } from '../logger.js'; import { isCSSRequest } from './dev/css.js'; -import { createRequest } from './request.js'; +import { canonicalURL as utilCanonicalURL } from '../util.js'; import { isScriptRequest } from './script.js'; function onlyAvailableInSSR(name: string) { @@ -26,8 +26,7 @@ export interface CreateResultArgs { site: string | undefined; links?: Set<SSRElement>; scripts?: Set<SSRElement>; - headers: Headers; - method: string; + request: Request; } class Slots { @@ -72,10 +71,10 @@ class Slots { } export function createResult(args: CreateResultArgs): SSRResult { - const { legacyBuild, markdownRender, method, origin, headers, params, pathname, renderers, resolve, site } = args; + const { legacyBuild, markdownRender, origin, params, pathname, renderers, request, resolve, site } = args; - const request = createRequest(method, pathname, headers, origin, site, args.ssr); - request.params = params; + const url = new URL(request.url); + const canonicalURL = utilCanonicalURL('.' + pathname, site ?? url.origin); // Create the result object that will be passed into the render function. // This object starts here as an empty shell (not yet the result) but then @@ -90,6 +89,8 @@ export function createResult(args: CreateResultArgs): SSRResult { const Astro = { __proto__: astroGlobal, + canonicalURL, + params, props, request, redirect: args.ssr diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts new file mode 100644 index 000000000..d0b711a9f --- /dev/null +++ b/packages/astro/src/core/request.ts @@ -0,0 +1,44 @@ +import type { IncomingHttpHeaders } from 'http'; +import type { LogOptions } from './logger'; +import { warn } from './logger.js'; + +type HeaderType = Headers | Record<string, any> | IncomingHttpHeaders; + +export interface CreateRequestOptions { + url: URL | string; + headers: HeaderType; + method?: string; + logging: LogOptions; +} + +export function createRequest({ + url, + headers, + method = 'GET', + logging +}: CreateRequestOptions): Request { + let headersObj = headers instanceof Headers ? headers : + new Headers(Object.entries(headers as Record<string, any>)); + + const request = new Request(url.toString(), { + method: method, + headers: headersObj + }); + + Object.defineProperties(request, { + canonicalURL: { + get() { + warn(logging, 'deprecation', `Astro.request.canonicalURL has been moved to Astro.canonicalURL`); + return undefined; + } + }, + params: { + get() { + warn(logging, 'deprecation', `Astro.request.params has been moved to Astro.params`); + return undefined; + } + } + }); + + return request; +} diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 957d3a1cc..7f314f721 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -1,6 +1,5 @@ import shorthash from 'shorthash'; import type { AstroComponentMetadata, AstroGlobalPartial, EndpointHandler, Params, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro'; -import type { AstroRequest } from '../../core/render/request'; import { escapeHTML, HTMLString, markHTMLString } from './escape.js'; import { extractDirectives, generateHydrateScript, serializeProps } from './hydration.js'; import { serializeListValue } from './util.js'; @@ -388,7 +387,7 @@ export function defineScriptVars(vars: Record<any, any>) { } // Renders an endpoint request to completion, returning the body. -export async function renderEndpoint(mod: EndpointHandler, request: AstroRequest, params: Params) { +export async function renderEndpoint(mod: EndpointHandler, request: Request, params: Params) { const chosenMethod = request.method?.toLowerCase() ?? 'get'; const handler = mod[chosenMethod]; diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 5b4ae41b8..66baf0d62 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -14,6 +14,7 @@ import notFoundTemplate, { subpathNotUsedTemplate } from '../template/4xx.js'; import serverErrorTemplate from '../template/5xx.js'; import { RouteCache } from '../core/render/route-cache.js'; import { fixViteErrorMessage } from '../core/errors.js'; +import { createRequest } from '../core/request.js'; interface AstroPluginOptions { config: AstroConfig; @@ -116,9 +117,24 @@ async function handleRequest( const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined; const devRoot = site ? site.pathname : '/'; const origin = `${viteServer.config.server.https ? 'https' : 'http'}://${req.headers.host}`; + const buildingToSSR = !!config._ctx.adapter?.serverEntrypoint; const url = new URL(origin + req.url); const pathname = decodeURI(url.pathname); const rootRelativeUrl = pathname.substring(devRoot.length - 1); + if(!buildingToSSR) { + // Prevent user from depending on search params when not doing SSR. + for(const [key] of url.searchParams) { + url.searchParams.delete(key); + } + } + + // Headers are only available when using SSR. + const request = createRequest({ + url, + headers: buildingToSSR ? req.headers : new Headers(), + method: req.method, + logging + }); try { if (!pathname.startsWith(devRoot)) { @@ -165,10 +181,9 @@ async function handleRequest( filePath: filePathCustom404, logging, mode: 'development', - method: 'GET', - headers: new Headers(Object.entries(req.headers as Record<string, any>)), origin, pathname: rootRelativeUrl, + request, route: routeCustom404, routeCache, viteServer, @@ -189,8 +204,7 @@ async function handleRequest( route, routeCache, viteServer, - method: req.method || 'GET', - headers: new Headers(Object.entries(req.headers as Record<string, any>)), + request, }; // Route successfully matched! Render it. diff --git a/packages/astro/src/vite-plugin-build-html/index.ts b/packages/astro/src/vite-plugin-build-html/index.ts index 80dd480a1..ad5b8ba14 100644 --- a/packages/astro/src/vite-plugin-build-html/index.ts +++ b/packages/astro/src/vite-plugin-build-html/index.ts @@ -17,6 +17,7 @@ import { getAstroPageStyleId, getAstroStyleId } from '../vite-plugin-build-css/i import { addRollupInput } from './add-rollup-input.js'; import { findAssets, findExternalScripts, findInlineScripts, findInlineStyles, getAttributes, getTextContent } from './extract-assets.js'; import { hasSrcSet, isBuildableImage, isBuildableLink, isHoistedScript, isInSrcDirectory } from './util.js'; +import { createRequest } from '../core/request.js'; // This package isn't real ESM, so have to coerce it const matchSrcset: typeof srcsetParse = (srcsetParse as any).default; @@ -87,8 +88,11 @@ export function rollupPluginAstroScanHTML(options: PluginOptions): VitePlugin { astroConfig, filePath: new URL(`./${component}`, astroConfig.projectRoot), logging, - headers: new Headers(), - method: 'GET', + request: createRequest({ + url: new URL(origin + pathname), + headers: new Headers(), + logging, + }), mode: 'production', origin, pathname, diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.test.js index eda1ce438..8330be821 100644 --- a/packages/astro/test/astro-global.test.js +++ b/packages/astro/test/astro-global.test.js @@ -25,7 +25,7 @@ describe('Astro.*', () => { expect($('#nested-child-pathname').text()).to.equal('/'); }); - it('Astro.request.canonicalURL', async () => { + it('Astro.canonicalURL', async () => { // given a URL, expect the following canonical URL const canonicalURLs = { '/index.html': 'https://mysite.dev/blog/', diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/[...calledTwiceTest].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/[...calledTwiceTest].astro index 19800e1ae..08b6af30c 100644 --- a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/[...calledTwiceTest].astro +++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/[...calledTwiceTest].astro @@ -10,7 +10,7 @@ export function getStaticPaths({ paginate }) { {params: {calledTwiceTest: 'c'}}, ]; } -const { params } = Astro.request; +const { params } = Astro; --- <html> diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/blog/[year]/[slug].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/blog/[year]/[slug].astro index b5c8ec282..12e686366 100644 --- a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/blog/[year]/[slug].astro +++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/blog/[year]/[slug].astro @@ -6,7 +6,7 @@ export async function getStaticPaths() { ] } -const { year, slug } = Astro.request.params +const { year, slug } = Astro.params --- <html> @@ -14,4 +14,4 @@ const { year, slug } = Astro.request.params <title>{year} | {slug}</title> </head> <body></body> -</html>
\ No newline at end of file +</html> diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[...pizza].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[...pizza].astro index 02ef8ef47..a58b314e3 100644 --- a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[...pizza].astro +++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[...pizza].astro @@ -8,7 +8,7 @@ export function getStaticPaths() { params: { pizza: 'grimaldis/new-york' }, }] } -const { pizza } = Astro.request.params +const { pizza } = Astro.params --- <html lang="en"> <head> @@ -19,4 +19,4 @@ const { pizza } = Astro.request.params <body> <h1>Welcome to {pizza ?? 'The landing page'}</h1> </body> -</html>
\ No newline at end of file +</html> diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[cheese]-[topping].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[cheese]-[topping].astro index 353805c5c..a698a76d7 100644 --- a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[cheese]-[topping].astro +++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/pizza/[cheese]-[topping].astro @@ -6,7 +6,7 @@ export function getStaticPaths() { params: { cheese: 'provolone', topping: 'sausage' }, }] } -const { cheese, topping } = Astro.request.params +const { cheese, topping } = Astro.params --- <html lang="en"> <head> @@ -18,4 +18,4 @@ const { cheese, topping } = Astro.request.params <h1>🍕 It's pizza time</h1> <p>{cheese}-{topping}</p> </body> -</html>
\ No newline at end of file +</html> diff --git a/packages/astro/test/fixtures/astro-global/src/components/Child.astro b/packages/astro/test/fixtures/astro-global/src/components/Child.astro index 28c84dab2..911e5464b 100644 --- a/packages/astro/test/fixtures/astro-global/src/components/Child.astro +++ b/packages/astro/test/fixtures/astro-global/src/components/Child.astro @@ -1,5 +1,5 @@ --- import NestedChild from './NestedChild.astro'; --- -<div id="child-pathname">{Astro.request.url.pathname}</div> -<NestedChild />
\ No newline at end of file +<div id="child-pathname">{new URL(Astro.request.url).pathname}</div> +<NestedChild /> diff --git a/packages/astro/test/fixtures/astro-global/src/components/NestedChild.astro b/packages/astro/test/fixtures/astro-global/src/components/NestedChild.astro index 9beea4278..809a0d68d 100644 --- a/packages/astro/test/fixtures/astro-global/src/components/NestedChild.astro +++ b/packages/astro/test/fixtures/astro-global/src/components/NestedChild.astro @@ -1 +1 @@ -<div id="nested-child-pathname">{Astro.request.url.pathname}</div>
\ No newline at end of file +<div id="nested-child-pathname">{new URL(Astro.request.url).pathname}</div> diff --git a/packages/astro/test/fixtures/astro-global/src/layouts/post.astro b/packages/astro/test/fixtures/astro-global/src/layouts/post.astro index 87e5cc448..ba9377278 100644 --- a/packages/astro/test/fixtures/astro-global/src/layouts/post.astro +++ b/packages/astro/test/fixtures/astro-global/src/layouts/post.astro @@ -4,7 +4,7 @@ const { content } = Astro.props; <html> <head> <title>{content.title}</title> - <link rel="canonical" href={Astro.request.canonicalURL.href}> + <link rel="canonical" href={Astro.canonicalURL.href}> </head> <body> <slot></slot> diff --git a/packages/astro/test/fixtures/astro-global/src/pages/index.astro b/packages/astro/test/fixtures/astro-global/src/pages/index.astro index 4906384c4..437495995 100644 --- a/packages/astro/test/fixtures/astro-global/src/pages/index.astro +++ b/packages/astro/test/fixtures/astro-global/src/pages/index.astro @@ -4,10 +4,10 @@ import Child from '../components/Child.astro'; <html> <head> <title>Test</title> - <link rel="canonical" href={Astro.request.canonicalURL.href}> + <link rel="canonical" href={Astro.canonicalURL.href}> </head> <body> - <div id="pathname">{Astro.request.url.pathname}</div> + <div id="pathname">{new URL(Astro.request.url).pathname}</div> <a id="site" href={Astro.site}>Home</a> <Child /> diff --git a/packages/astro/test/fixtures/astro-global/src/pages/posts/[page].astro b/packages/astro/test/fixtures/astro-global/src/pages/posts/[page].astro index 1cd1c6881..1a21cf475 100644 --- a/packages/astro/test/fixtures/astro-global/src/pages/posts/[page].astro +++ b/packages/astro/test/fixtures/astro-global/src/pages/posts/[page].astro @@ -4,7 +4,7 @@ export async function getStaticPaths({paginate}) { return paginate(data, {pageSize: 1}); } const { page } = Astro.props; -const { params, canonicalURL} = Astro.request; +const { params, canonicalURL} = Astro; --- <html> diff --git a/packages/astro/test/fixtures/astro-pagination/src/pages/index.astro b/packages/astro/test/fixtures/astro-pagination/src/pages/index.astro index db72daff5..afd2203de 100644 --- a/packages/astro/test/fixtures/astro-pagination/src/pages/index.astro +++ b/packages/astro/test/fixtures/astro-pagination/src/pages/index.astro @@ -3,10 +3,10 @@ <html> <head> <title>Test</title> - <link rel="canonical" href={Astro.request.canonicalURL.href}> + <link rel="canonical" href={Astro.canonicalURL.href}> </head> <body> - <div id="pathname">{Astro.request.url.pathname}</div> + <div id="pathname">{new URL(Astro.request.url).pathname}</div> <a id="site" href={Astro.site}>Home</a> </body> </html> diff --git a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/[slug]/[page].astro b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/[slug]/[page].astro index 1b701517f..ba51548a1 100644 --- a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/[slug]/[page].astro +++ b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/[slug]/[page].astro @@ -11,7 +11,7 @@ export async function getStaticPaths({paginate}) { }); } const { page, filter } = Astro.props; -const { params, canonicalURL} = Astro.request; +const { params, canonicalURL} = Astro; --- <html> diff --git a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/named-root-page/[page].astro b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/named-root-page/[page].astro index fef4cc887..a3efb9b45 100644 --- a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/named-root-page/[page].astro +++ b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/named-root-page/[page].astro @@ -4,7 +4,7 @@ export async function getStaticPaths({paginate}) { return paginate(data, {pageSize: 1}); } const { page } = Astro.props; -const { params, canonicalURL} = Astro.request; +const { params, canonicalURL} = Astro; --- <html> diff --git a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/optional-root-page/[...page].astro b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/optional-root-page/[...page].astro index fef4cc887..a3efb9b45 100644 --- a/packages/astro/test/fixtures/astro-pagination/src/pages/posts/optional-root-page/[...page].astro +++ b/packages/astro/test/fixtures/astro-pagination/src/pages/posts/optional-root-page/[...page].astro @@ -4,7 +4,7 @@ export async function getStaticPaths({paginate}) { return paginate(data, {pageSize: 1}); } const { page } = Astro.props; -const { params, canonicalURL} = Astro.request; +const { params, canonicalURL} = Astro; --- <html> diff --git a/packages/astro/test/fixtures/ssr-dynamic/src/pages/[id].astro b/packages/astro/test/fixtures/ssr-dynamic/src/pages/[id].astro index b976757e2..e64626172 100644 --- a/packages/astro/test/fixtures/ssr-dynamic/src/pages/[id].astro +++ b/packages/astro/test/fixtures/ssr-dynamic/src/pages/[id].astro @@ -1,5 +1,5 @@ --- -const val = Number(Astro.request.params.id); +const val = Number(Astro.params.id); --- <html> <head> |