diff options
author | 2021-04-27 14:00:33 -0400 | |
---|---|---|
committer | 2021-04-27 14:00:33 -0400 | |
commit | 41c64b30af7ed34c1a870b6f273a2889fa2df102 (patch) | |
tree | 5bbaf30bcb43ec5d4eb47e9188b639c3298c6f3b /src | |
parent | dea1a6dfc9dec54034d2b872b4cd36c0174814c6 (diff) | |
download | astro-41c64b30af7ed34c1a870b6f273a2889fa2df102.tar.gz astro-41c64b30af7ed34c1a870b6f273a2889fa2df102.tar.zst astro-41c64b30af7ed34c1a870b6f273a2889fa2df102.zip |
Move the `request` object from import.meta to Astro (#134)
* Move the `request` object from import.meta to Astro
This moves the `request` object to the Astro "global" (really just a render-level variable).
* Document Astro.request
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/index.ts | 7 | ||||
-rw-r--r-- | src/frontend/500.astro | 2 | ||||
-rw-r--r-- | src/runtime.ts | 4 |
3 files changed, 8 insertions, 5 deletions
diff --git a/src/compiler/index.ts b/src/compiler/index.ts index d2d7bff08..7e7bfc4c6 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -131,7 +131,12 @@ ${result.imports.join('\n')} // \`__render()\`: Render the contents of the Astro module. import { h, Fragment } from '${internalImport('h.js')}'; +const __astroRequestSymbol = Symbol('astro.request'); async function __render(props, ...children) { + const Astro = { + request: props[__astroRequestSymbol] + }; + ${result.script} return h(Fragment, null, ${result.html}); } @@ -148,7 +153,7 @@ export async function __renderPage({request, children, props}) { __render, }; - import.meta.request = request; + props[__astroRequestSymbol] = request; const childBodyResult = await currentChild.__render(props, children); // find layout, if one was given. diff --git a/src/frontend/500.astro b/src/frontend/500.astro index af7b901e9..01fab8bea 100644 --- a/src/frontend/500.astro +++ b/src/frontend/500.astro @@ -2,7 +2,7 @@ import Prism from 'astro/components/Prism.astro'; let title = 'Uh oh...'; -const error = import.meta.request.url.searchParams.get('error'); +const error = Astro.request.url.searchParams.get('error'); --- <!doctype html> diff --git a/src/runtime.ts b/src/runtime.ts index a394d93c4..d7f63183c 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -205,9 +205,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro let html = (await mod.exports.__renderPage({ request: { - host: fullurl.hostname, - path: fullurl.pathname, - href: fullurl.toString(), + // params should go here when implemented url: requestURL }, children: [], |