0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

[ci] format

This commit is contained in:
matthewp 2022-03-29 11:36:02 +00:00 committed by GitHub Actions
parent ecc6a4833f
commit f0275298bd
3 changed files with 11 additions and 18 deletions

View file

@ -3,8 +3,7 @@ import type { RenderOptions } from '../render/core';
import { renderEndpoint } from '../../runtime/server/index.js'; import { renderEndpoint } from '../../runtime/server/index.js';
import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js'; import { getParamsAndProps, GetParamsAndPropsError } from '../render/core.js';
export type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | export type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr'>;
'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr'>;
type EndpointCallResult = type EndpointCallResult =
| { | {

View file

@ -11,18 +11,12 @@ export interface CreateRequestOptions {
logging: LogOptions; logging: LogOptions;
} }
export function createRequest({ export function createRequest({ url, headers, method = 'GET', logging }: CreateRequestOptions): Request {
url, let headersObj = headers instanceof Headers ? headers : new Headers(Object.entries(headers as Record<string, any>));
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(), { const request = new Request(url.toString(), {
method: method, method: method,
headers: headersObj headers: headersObj,
}); });
Object.defineProperties(request, { Object.defineProperties(request, {
@ -30,14 +24,14 @@ export function createRequest({
get() { get() {
warn(logging, 'deprecation', `Astro.request.canonicalURL has been moved to Astro.canonicalURL`); warn(logging, 'deprecation', `Astro.request.canonicalURL has been moved to Astro.canonicalURL`);
return undefined; return undefined;
} },
}, },
params: { params: {
get() { get() {
warn(logging, 'deprecation', `Astro.request.params has been moved to Astro.params`); warn(logging, 'deprecation', `Astro.request.params has been moved to Astro.params`);
return undefined; return undefined;
} },
} },
}); });
return request; return request;

View file

@ -121,9 +121,9 @@ async function handleRequest(
const url = new URL(origin + req.url); const url = new URL(origin + req.url);
const pathname = decodeURI(url.pathname); const pathname = decodeURI(url.pathname);
const rootRelativeUrl = pathname.substring(devRoot.length - 1); const rootRelativeUrl = pathname.substring(devRoot.length - 1);
if(!buildingToSSR) { if (!buildingToSSR) {
// Prevent user from depending on search params when not doing SSR. // Prevent user from depending on search params when not doing SSR.
for(const [key] of url.searchParams) { for (const [key] of url.searchParams) {
url.searchParams.delete(key); url.searchParams.delete(key);
} }
} }
@ -133,7 +133,7 @@ async function handleRequest(
url, url,
headers: buildingToSSR ? req.headers : new Headers(), headers: buildingToSSR ? req.headers : new Headers(),
method: req.method, method: req.method,
logging logging,
}); });
try { try {