full site update
This commit is contained in:
2
node_modules/astro/dist/core/app/common.d.ts
generated
vendored
2
node_modules/astro/dist/core/app/common.d.ts
generated
vendored
@@ -1,2 +1,2 @@
|
||||
import type { SSRManifest, SerializedSSRManifest } from './types.js';
|
||||
import type { SerializedSSRManifest, SSRManifest } from './types.js';
|
||||
export declare function deserializeManifest(serializedManifest: SerializedSSRManifest): SSRManifest;
|
||||
|
34
node_modules/astro/dist/core/app/index.d.ts
generated
vendored
34
node_modules/astro/dist/core/app/index.d.ts
generated
vendored
@@ -1,7 +1,9 @@
|
||||
import type { ManifestData, RouteData, SSRManifest } from '../../@types/astro.js';
|
||||
import type { RoutesList } from '../../types/astro.js';
|
||||
import type { RouteData, SSRManifest } from '../../types/public/internal.js';
|
||||
import { getSetCookiesFromResponse } from '../cookies/index.js';
|
||||
import { AstroIntegrationLogger } from '../logger/core.js';
|
||||
export { deserializeManifest } from './common.js';
|
||||
type ErrorPagePath = `${string}/404` | `${string}/500` | `${string}/404/` | `${string}/500/` | `${string}404.html` | `${string}500.html`;
|
||||
export interface RenderOptions {
|
||||
/**
|
||||
* Whether to automatically add all cookies written by `Astro.cookie.set()` to the response headers.
|
||||
@@ -23,6 +25,19 @@ export interface RenderOptions {
|
||||
* The mutable object that will be made available as `Astro.locals` in pages, and as `ctx.locals` in API routes and middleware.
|
||||
*/
|
||||
locals?: object;
|
||||
/**
|
||||
* A custom fetch function for retrieving prerendered pages - 404 or 500.
|
||||
*
|
||||
* If not provided, Astro will fallback to its default behavior for fetching error pages.
|
||||
*
|
||||
* When a dynamic route is matched but ultimately results in a 404, this function will be used
|
||||
* to fetch the prerendered 404 page if available. Similarly, it may be used to fetch a
|
||||
* prerendered 500 error page when necessary.
|
||||
*
|
||||
* @param {ErrorPagePath} url - The URL of the prerendered 404 or 500 error page to fetch.
|
||||
* @returns {Promise<Response>} A promise resolving to the prerendered response.
|
||||
*/
|
||||
prerenderedErrorPageFetch?: (url: ErrorPagePath) => Promise<Response>;
|
||||
/**
|
||||
* **Advanced API**: you probably do not need to use this.
|
||||
*
|
||||
@@ -43,20 +58,25 @@ export interface RenderErrorOptions {
|
||||
* Allows passing an error to 500.astro. It will be available through `Astro.props.error`.
|
||||
*/
|
||||
error?: unknown;
|
||||
clientAddress: string | undefined;
|
||||
prerenderedErrorPageFetch: (url: ErrorPagePath) => Promise<Response>;
|
||||
}
|
||||
export declare class App {
|
||||
#private;
|
||||
constructor(manifest: SSRManifest, streaming?: boolean);
|
||||
getAdapterLogger(): AstroIntegrationLogger;
|
||||
set setManifestData(newManifestData: ManifestData);
|
||||
set setManifestData(newManifestData: RoutesList);
|
||||
removeBase(pathname: string): string;
|
||||
match(request: Request): RouteData | undefined;
|
||||
render(request: Request, options?: RenderOptions): Promise<Response>;
|
||||
/**
|
||||
* @deprecated Instead of passing `RouteData` and locals individually, pass an object with `routeData` and `locals` properties.
|
||||
* See https://github.com/withastro/astro/pull/9199 for more information.
|
||||
* Given a `Request`, it returns the `RouteData` that matches its `pathname`. By default, prerendered
|
||||
* routes aren't returned, even if they are matched.
|
||||
*
|
||||
* When `allowPrerenderedRoutes` is `true`, the function returns matched prerendered routes too.
|
||||
* @param request
|
||||
* @param allowPrerenderedRoutes
|
||||
*/
|
||||
render(request: Request, routeData?: RouteData, locals?: object): Promise<Response>;
|
||||
match(request: Request, allowPrerenderedRoutes?: boolean): RouteData | undefined;
|
||||
render(request: Request, renderOptions?: RenderOptions): Promise<Response>;
|
||||
setCookieHeaders(response: Response): Generator<string, string[], any>;
|
||||
/**
|
||||
* Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
|
||||
|
214
node_modules/astro/dist/core/app/index.js
generated
vendored
214
node_modules/astro/dist/core/app/index.js
generated
vendored
@@ -1,9 +1,10 @@
|
||||
import { collapseDuplicateTrailingSlashes, hasFileExtension } from "@astrojs/internal-helpers/path";
|
||||
import { normalizeTheLocale } from "../../i18n/index.js";
|
||||
import {
|
||||
clientAddressSymbol,
|
||||
DEFAULT_404_COMPONENT,
|
||||
REROUTABLE_STATUS_CODES,
|
||||
REROUTE_DIRECTIVE_HEADER,
|
||||
clientAddressSymbol,
|
||||
clientLocalsSymbol,
|
||||
responseSentSymbol
|
||||
} from "../constants.js";
|
||||
import { getSetCookiesFromResponse } from "../cookies/index.js";
|
||||
@@ -17,10 +18,13 @@ import {
|
||||
prependForwardSlash,
|
||||
removeTrailingForwardSlash
|
||||
} from "../path.js";
|
||||
import { RenderContext } from "../render-context.js";
|
||||
import { createAssetLink } from "../render/ssr-element.js";
|
||||
import { createDefaultRoutes, injectDefaultRoutes } from "../routing/default.js";
|
||||
import { RenderContext } from "../render-context.js";
|
||||
import { redirectTemplate } from "../routing/3xx.js";
|
||||
import { ensure404Route } from "../routing/astro-designed-error-pages.js";
|
||||
import { createDefaultRoutes } from "../routing/default.js";
|
||||
import { matchRoute } from "../routing/match.js";
|
||||
import { PERSIST_SYMBOL } from "../session.js";
|
||||
import { AppPipeline } from "./pipeline.js";
|
||||
import { deserializeManifest } from "./common.js";
|
||||
class App {
|
||||
@@ -33,14 +37,14 @@ class App {
|
||||
#baseWithoutTrailingSlash;
|
||||
#pipeline;
|
||||
#adapterLogger;
|
||||
#renderOptionsDeprecationWarningShown = false;
|
||||
constructor(manifest, streaming = true) {
|
||||
this.#manifest = manifest;
|
||||
this.#manifestData = injectDefaultRoutes(manifest, {
|
||||
this.#manifestData = {
|
||||
routes: manifest.routes.map((route) => route.routeData)
|
||||
});
|
||||
};
|
||||
ensure404Route(this.#manifestData);
|
||||
this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
|
||||
this.#pipeline = this.#createPipeline(this.#manifestData, streaming);
|
||||
this.#pipeline = this.#createPipeline(streaming);
|
||||
this.#adapterLogger = new AstroIntegrationLogger(
|
||||
this.#logger.options,
|
||||
this.#manifest.adapterName
|
||||
@@ -52,15 +56,14 @@ class App {
|
||||
/**
|
||||
* Creates a pipeline by reading the stored manifest
|
||||
*
|
||||
* @param manifestData
|
||||
* @param streaming
|
||||
* @private
|
||||
*/
|
||||
#createPipeline(manifestData, streaming = false) {
|
||||
return AppPipeline.create(manifestData, {
|
||||
#createPipeline(streaming = false) {
|
||||
return AppPipeline.create({
|
||||
logger: this.#logger,
|
||||
manifest: this.#manifest,
|
||||
mode: "production",
|
||||
runtimeMode: "production",
|
||||
renderers: this.#manifest.renderers,
|
||||
defaultRoutes: createDefaultRoutes(this.#manifest),
|
||||
resolve: async (specifier) => {
|
||||
@@ -87,20 +90,45 @@ class App {
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
/**
|
||||
* It removes the base from the request URL, prepends it with a forward slash and attempts to decoded it.
|
||||
*
|
||||
* If the decoding fails, it logs the error and return the pathname as is.
|
||||
* @param request
|
||||
* @private
|
||||
*/
|
||||
#getPathnameFromRequest(request) {
|
||||
const url = new URL(request.url);
|
||||
const pathname = prependForwardSlash(this.removeBase(url.pathname));
|
||||
return pathname;
|
||||
try {
|
||||
return decodeURI(pathname);
|
||||
} catch (e) {
|
||||
this.getAdapterLogger().error(e.toString());
|
||||
return pathname;
|
||||
}
|
||||
}
|
||||
match(request) {
|
||||
/**
|
||||
* Given a `Request`, it returns the `RouteData` that matches its `pathname`. By default, prerendered
|
||||
* routes aren't returned, even if they are matched.
|
||||
*
|
||||
* When `allowPrerenderedRoutes` is `true`, the function returns matched prerendered routes too.
|
||||
* @param request
|
||||
* @param allowPrerenderedRoutes
|
||||
*/
|
||||
match(request, allowPrerenderedRoutes = false) {
|
||||
const url = new URL(request.url);
|
||||
if (this.#manifest.assets.has(url.pathname)) return void 0;
|
||||
let pathname = this.#computePathnameFromDomain(request);
|
||||
if (!pathname) {
|
||||
pathname = prependForwardSlash(this.removeBase(url.pathname));
|
||||
}
|
||||
let routeData = matchRoute(pathname, this.#manifestData);
|
||||
if (!routeData || routeData.prerender) return void 0;
|
||||
let routeData = matchRoute(decodeURI(pathname), this.#manifestData);
|
||||
if (!routeData) return void 0;
|
||||
if (allowPrerenderedRoutes) {
|
||||
return routeData;
|
||||
} else if (routeData.prerender) {
|
||||
return void 0;
|
||||
}
|
||||
return routeData;
|
||||
}
|
||||
#computePathnameFromDomain(request) {
|
||||
@@ -150,31 +178,55 @@ class App {
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
async render(request, routeDataOrOptions, maybeLocals) {
|
||||
#redirectTrailingSlash(pathname) {
|
||||
const { trailingSlash } = this.#manifest;
|
||||
if (pathname === "/" || pathname.startsWith("/_")) {
|
||||
return pathname;
|
||||
}
|
||||
const path = collapseDuplicateTrailingSlashes(pathname, trailingSlash !== "never");
|
||||
if (path !== pathname) {
|
||||
return path;
|
||||
}
|
||||
if (trailingSlash === "ignore") {
|
||||
return pathname;
|
||||
}
|
||||
if (trailingSlash === "always" && !hasFileExtension(pathname)) {
|
||||
return appendForwardSlash(pathname);
|
||||
}
|
||||
if (trailingSlash === "never") {
|
||||
return removeTrailingForwardSlash(pathname);
|
||||
}
|
||||
return pathname;
|
||||
}
|
||||
async render(request, renderOptions) {
|
||||
let routeData;
|
||||
let locals;
|
||||
let clientAddress;
|
||||
let addCookieHeader;
|
||||
if (routeDataOrOptions && ("addCookieHeader" in routeDataOrOptions || "clientAddress" in routeDataOrOptions || "locals" in routeDataOrOptions || "routeData" in routeDataOrOptions)) {
|
||||
if ("addCookieHeader" in routeDataOrOptions) {
|
||||
addCookieHeader = routeDataOrOptions.addCookieHeader;
|
||||
}
|
||||
if ("clientAddress" in routeDataOrOptions) {
|
||||
clientAddress = routeDataOrOptions.clientAddress;
|
||||
}
|
||||
if ("routeData" in routeDataOrOptions) {
|
||||
routeData = routeDataOrOptions.routeData;
|
||||
}
|
||||
if ("locals" in routeDataOrOptions) {
|
||||
locals = routeDataOrOptions.locals;
|
||||
}
|
||||
} else {
|
||||
routeData = routeDataOrOptions;
|
||||
locals = maybeLocals;
|
||||
if (routeDataOrOptions || locals) {
|
||||
this.#logRenderOptionsDeprecationWarning();
|
||||
}
|
||||
const url = new URL(request.url);
|
||||
const redirect = this.#redirectTrailingSlash(url.pathname);
|
||||
const prerenderedErrorPageFetch = renderOptions?.prerenderedErrorPageFetch ?? fetch;
|
||||
if (redirect !== url.pathname) {
|
||||
const status = request.method === "GET" ? 301 : 308;
|
||||
return new Response(
|
||||
redirectTemplate({
|
||||
status,
|
||||
relativeLocation: url.pathname,
|
||||
absoluteLocation: redirect,
|
||||
from: request.url
|
||||
}),
|
||||
{
|
||||
status,
|
||||
headers: {
|
||||
location: redirect + url.search
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
addCookieHeader = renderOptions?.addCookieHeader;
|
||||
clientAddress = renderOptions?.clientAddress ?? Reflect.get(request, clientAddressSymbol);
|
||||
routeData = renderOptions?.routeData;
|
||||
locals = renderOptions?.locals;
|
||||
if (routeData) {
|
||||
this.#logger.debug(
|
||||
"router",
|
||||
@@ -187,26 +239,38 @@ class App {
|
||||
if (typeof locals !== "object") {
|
||||
const error = new AstroError(AstroErrorData.LocalsNotAnObject);
|
||||
this.#logger.error(null, error.stack);
|
||||
return this.#renderError(request, { status: 500, error });
|
||||
return this.#renderError(request, {
|
||||
status: 500,
|
||||
error,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
});
|
||||
}
|
||||
Reflect.set(request, clientLocalsSymbol, locals);
|
||||
}
|
||||
if (clientAddress) {
|
||||
Reflect.set(request, clientAddressSymbol, clientAddress);
|
||||
}
|
||||
if (!routeData) {
|
||||
routeData = this.match(request);
|
||||
this.#logger.debug("router", "Astro matched the following route for " + request.url);
|
||||
this.#logger.debug("router", "RouteData:\n" + routeData);
|
||||
}
|
||||
if (!routeData) {
|
||||
routeData = this.#manifestData.routes.find(
|
||||
(route) => route.component === "404.astro" || route.component === DEFAULT_404_COMPONENT
|
||||
);
|
||||
}
|
||||
if (!routeData) {
|
||||
this.#logger.debug("router", "Astro hasn't found routes that match " + request.url);
|
||||
this.#logger.debug("router", "Here's the available routes:\n", this.#manifestData);
|
||||
return this.#renderError(request, { locals, status: 404 });
|
||||
return this.#renderError(request, {
|
||||
locals,
|
||||
status: 404,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
});
|
||||
}
|
||||
const pathname = this.#getPathnameFromRequest(request);
|
||||
const defaultStatus = this.#getDefaultStatusCode(routeData, pathname);
|
||||
let response;
|
||||
let session;
|
||||
try {
|
||||
const mod = await this.#pipeline.getModuleForRoute(routeData);
|
||||
const renderContext = await RenderContext.create({
|
||||
@@ -215,12 +279,22 @@ class App {
|
||||
pathname,
|
||||
request,
|
||||
routeData,
|
||||
status: defaultStatus
|
||||
status: defaultStatus,
|
||||
clientAddress
|
||||
});
|
||||
session = renderContext.session;
|
||||
response = await renderContext.render(await mod.page());
|
||||
} catch (err) {
|
||||
this.#logger.error(null, err.stack || err.message || String(err));
|
||||
return this.#renderError(request, { locals, status: 500, error: err });
|
||||
return this.#renderError(request, {
|
||||
locals,
|
||||
status: 500,
|
||||
error: err,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
});
|
||||
} finally {
|
||||
await session?.[PERSIST_SYMBOL]();
|
||||
}
|
||||
if (REROUTABLE_STATUS_CODES.includes(response.status) && response.headers.get(REROUTE_DIRECTIVE_HEADER) !== "no") {
|
||||
return this.#renderError(request, {
|
||||
@@ -229,7 +303,9 @@ class App {
|
||||
status: response.status,
|
||||
// We don't have an error to report here. Passing null means we pass nothing intentionally
|
||||
// while undefined means there's no error
|
||||
error: response.status === 500 ? null : void 0
|
||||
error: response.status === 500 ? null : void 0,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
});
|
||||
}
|
||||
if (response.headers.has(REROUTE_DIRECTIVE_HEADER)) {
|
||||
@@ -243,14 +319,6 @@ class App {
|
||||
Reflect.set(response, responseSentSymbol, true);
|
||||
return response;
|
||||
}
|
||||
#logRenderOptionsDeprecationWarning() {
|
||||
if (this.#renderOptionsDeprecationWarningShown) return;
|
||||
this.#logger.warn(
|
||||
"deprecated",
|
||||
`The adapter ${this.#manifest.adapterName} is using a deprecated signature of the 'app.render()' method. From Astro 4.0, locals and routeData are provided as properties on an optional object to this method. Using the old signature will cause an error in Astro 5.0. See https://github.com/withastro/astro/pull/9199 for more information.`
|
||||
);
|
||||
this.#renderOptionsDeprecationWarningShown = true;
|
||||
}
|
||||
setCookieHeaders(response) {
|
||||
return getSetCookiesFromResponse(response);
|
||||
}
|
||||
@@ -275,7 +343,9 @@ class App {
|
||||
status,
|
||||
response: originalResponse,
|
||||
skipMiddleware = false,
|
||||
error
|
||||
error,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
}) {
|
||||
const errorRoutePath = `/${status}${this.#manifest.trailingSlash === "always" ? "/" : ""}`;
|
||||
const errorRouteData = matchRoute(errorRoutePath, this.#manifestData);
|
||||
@@ -288,12 +358,13 @@ class App {
|
||||
url
|
||||
);
|
||||
if (statusURL.toString() !== request.url) {
|
||||
const response2 = await fetch(statusURL.toString());
|
||||
const override = { status };
|
||||
const response2 = await prerenderedErrorPageFetch(statusURL.toString());
|
||||
const override = { status, removeContentEncodingHeaders: true };
|
||||
return this.#mergeResponses(response2, originalResponse, override);
|
||||
}
|
||||
}
|
||||
const mod = await this.#pipeline.getModuleForRoute(errorRouteData);
|
||||
let session;
|
||||
try {
|
||||
const renderContext = await RenderContext.create({
|
||||
locals,
|
||||
@@ -303,8 +374,10 @@ class App {
|
||||
request,
|
||||
routeData: errorRouteData,
|
||||
status,
|
||||
props: { error }
|
||||
props: { error },
|
||||
clientAddress
|
||||
});
|
||||
session = renderContext.session;
|
||||
const response2 = await renderContext.render(await mod.page());
|
||||
return this.#mergeResponses(response2, originalResponse);
|
||||
} catch {
|
||||
@@ -313,9 +386,13 @@ class App {
|
||||
locals,
|
||||
status,
|
||||
response: originalResponse,
|
||||
skipMiddleware: true
|
||||
skipMiddleware: true,
|
||||
clientAddress,
|
||||
prerenderedErrorPageFetch
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await session?.[PERSIST_SYMBOL]();
|
||||
}
|
||||
}
|
||||
const response = this.#mergeResponses(new Response(null, { status }), originalResponse);
|
||||
@@ -323,12 +400,18 @@ class App {
|
||||
return response;
|
||||
}
|
||||
#mergeResponses(newResponse, originalResponse, override) {
|
||||
let newResponseHeaders = newResponse.headers;
|
||||
if (override?.removeContentEncodingHeaders) {
|
||||
newResponseHeaders = new Headers(newResponseHeaders);
|
||||
newResponseHeaders.delete("Content-Encoding");
|
||||
newResponseHeaders.delete("Content-Length");
|
||||
}
|
||||
if (!originalResponse) {
|
||||
if (override !== void 0) {
|
||||
return new Response(newResponse.body, {
|
||||
status: override.status,
|
||||
statusText: newResponse.statusText,
|
||||
headers: newResponse.headers
|
||||
headers: newResponseHeaders
|
||||
});
|
||||
}
|
||||
return newResponse;
|
||||
@@ -338,6 +421,14 @@ class App {
|
||||
originalResponse.headers.delete("Content-type");
|
||||
} catch {
|
||||
}
|
||||
const mergedHeaders = new Map([
|
||||
...Array.from(newResponseHeaders),
|
||||
...Array.from(originalResponse.headers)
|
||||
]);
|
||||
const newHeaders = new Headers();
|
||||
for (const [name, value] of mergedHeaders) {
|
||||
newHeaders.set(name, value);
|
||||
}
|
||||
return new Response(newResponse.body, {
|
||||
status,
|
||||
statusText: status === 200 ? newResponse.statusText : originalResponse.statusText,
|
||||
@@ -346,10 +437,7 @@ class App {
|
||||
// If users see something weird, it's because they are setting some headers they should not.
|
||||
//
|
||||
// Although, we don't want it to replace the content-type, because the error page must return `text/html`
|
||||
headers: new Headers([
|
||||
...Array.from(newResponse.headers),
|
||||
...Array.from(originalResponse.headers)
|
||||
])
|
||||
headers: newHeaders
|
||||
});
|
||||
}
|
||||
#getDefaultStatusCode(routeData, pathname) {
|
||||
|
2
node_modules/astro/dist/core/app/middlewares.d.ts
generated
vendored
2
node_modules/astro/dist/core/app/middlewares.d.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import type { MiddlewareHandler } from '../../@types/astro.js';
|
||||
import type { MiddlewareHandler } from '../../types/public/common.js';
|
||||
/**
|
||||
* Returns a middleware function in charge to check the `origin` header.
|
||||
*
|
||||
|
14
node_modules/astro/dist/core/app/middlewares.js
generated
vendored
14
node_modules/astro/dist/core/app/middlewares.js
generated
vendored
@@ -4,23 +4,27 @@ const FORM_CONTENT_TYPES = [
|
||||
"multipart/form-data",
|
||||
"text/plain"
|
||||
];
|
||||
const SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
|
||||
function createOriginCheckMiddleware() {
|
||||
return defineMiddleware((context, next) => {
|
||||
const { request, url } = context;
|
||||
if (request.method === "GET") {
|
||||
const { request, url, isPrerendered } = context;
|
||||
if (isPrerendered) {
|
||||
return next();
|
||||
}
|
||||
const sameOrigin = (request.method === "POST" || request.method === "PUT" || request.method === "PATCH" || request.method === "DELETE") && request.headers.get("origin") === url.origin;
|
||||
if (SAFE_METHODS.includes(request.method)) {
|
||||
return next();
|
||||
}
|
||||
const isSameOrigin = request.headers.get("origin") === url.origin;
|
||||
const hasContentType = request.headers.has("content-type");
|
||||
if (hasContentType) {
|
||||
const formLikeHeader = hasFormLikeHeader(request.headers.get("content-type"));
|
||||
if (formLikeHeader && !sameOrigin) {
|
||||
if (formLikeHeader && !isSameOrigin) {
|
||||
return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
|
||||
status: 403
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (!sameOrigin) {
|
||||
if (!isSameOrigin) {
|
||||
return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
|
||||
status: 403
|
||||
});
|
||||
|
10
node_modules/astro/dist/core/app/node.d.ts
generated
vendored
10
node_modules/astro/dist/core/app/node.d.ts
generated
vendored
@@ -1,8 +1,8 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||
import type { RouteData } from '../../@types/astro.js';
|
||||
import { App } from './index.js';
|
||||
import type { RouteData } from '../../types/public/internal.js';
|
||||
import type { RenderOptions } from './index.js';
|
||||
import type { SSRManifest } from './types.js';
|
||||
import { App } from './index.js';
|
||||
import type { NodeAppHeadersJson, SSRManifest } from './types.js';
|
||||
export { apply as applyPolyfills } from '../polyfill.js';
|
||||
/**
|
||||
* Allow the request body to be explicitly overridden. For example, this
|
||||
@@ -12,7 +12,9 @@ interface NodeRequest extends IncomingMessage {
|
||||
body?: unknown;
|
||||
}
|
||||
export declare class NodeApp extends App {
|
||||
match(req: NodeRequest | Request): RouteData | undefined;
|
||||
headersMap: NodeAppHeadersJson | undefined;
|
||||
setHeadersMap(headers: NodeAppHeadersJson): void;
|
||||
match(req: NodeRequest | Request, allowPrerenderedRoutes?: boolean): RouteData | undefined;
|
||||
render(request: NodeRequest | Request, options?: RenderOptions): Promise<Response>;
|
||||
/**
|
||||
* @deprecated Instead of passing `RouteData` and locals individually, pass an object with `routeData` and `locals` properties.
|
||||
|
30
node_modules/astro/dist/core/app/node.js
generated
vendored
30
node_modules/astro/dist/core/app/node.js
generated
vendored
@@ -6,13 +6,17 @@ import { createOutgoingHttpHeaders } from "./createOutgoingHttpHeaders.js";
|
||||
import { App } from "./index.js";
|
||||
import { apply } from "../polyfill.js";
|
||||
class NodeApp extends App {
|
||||
match(req) {
|
||||
headersMap = void 0;
|
||||
setHeadersMap(headers) {
|
||||
this.headersMap = headers;
|
||||
}
|
||||
match(req, allowPrerenderedRoutes = false) {
|
||||
if (!(req instanceof Request)) {
|
||||
req = NodeApp.createRequest(req, {
|
||||
skipBody: true
|
||||
});
|
||||
}
|
||||
return super.match(req);
|
||||
return super.match(req, allowPrerenderedRoutes);
|
||||
}
|
||||
render(req, routeDataOrOptions, maybeLocals) {
|
||||
if (!(req instanceof Request)) {
|
||||
@@ -39,13 +43,20 @@ class NodeApp extends App {
|
||||
return multiValueHeader?.toString()?.split(",").map((e) => e.trim())?.[0];
|
||||
};
|
||||
const forwardedProtocol = getFirstForwardedValue(req.headers["x-forwarded-proto"]);
|
||||
const protocol = forwardedProtocol ?? (isEncrypted ? "https" : "http");
|
||||
const providedProtocol = isEncrypted ? "https" : "http";
|
||||
const protocol = forwardedProtocol ?? providedProtocol;
|
||||
const forwardedHostname = getFirstForwardedValue(req.headers["x-forwarded-host"]);
|
||||
const hostname = forwardedHostname ?? req.headers.host ?? req.headers[":authority"];
|
||||
const providedHostname = req.headers.host ?? req.headers[":authority"];
|
||||
const hostname = forwardedHostname ?? providedHostname;
|
||||
const port = getFirstForwardedValue(req.headers["x-forwarded-port"]);
|
||||
const portInHostname = typeof hostname === "string" && /:\d+$/.test(hostname);
|
||||
const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ""}`;
|
||||
const url = `${protocol}://${hostnamePort}${req.url}`;
|
||||
let url;
|
||||
try {
|
||||
const hostnamePort = getHostnamePort(hostname, port);
|
||||
url = new URL(`${protocol}://${hostnamePort}${req.url}`);
|
||||
} catch {
|
||||
const hostnamePort = getHostnamePort(providedHostname, port);
|
||||
url = new URL(`${providedProtocol}://${hostnamePort}`);
|
||||
}
|
||||
const options = {
|
||||
method: req.method || "GET",
|
||||
headers: makeRequestHeaders(req)
|
||||
@@ -107,6 +118,11 @@ class NodeApp extends App {
|
||||
}
|
||||
}
|
||||
}
|
||||
function getHostnamePort(hostname, port) {
|
||||
const portInHostname = typeof hostname === "string" && /:\d+$/.test(hostname);
|
||||
const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ""}`;
|
||||
return hostnamePort;
|
||||
}
|
||||
function makeRequestHeaders(req) {
|
||||
const headers = new Headers();
|
||||
for (const [name, value] of Object.entries(req.headers)) {
|
||||
|
7
node_modules/astro/dist/core/app/pipeline.d.ts
generated
vendored
7
node_modules/astro/dist/core/app/pipeline.d.ts
generated
vendored
@@ -1,9 +1,10 @@
|
||||
import type { ComponentInstance, ManifestData, RewritePayload, RouteData, SSRResult } from '../../@types/astro.js';
|
||||
import type { ComponentInstance } from '../../types/astro.js';
|
||||
import type { RewritePayload } from '../../types/public/common.js';
|
||||
import type { RouteData, SSRResult } from '../../types/public/internal.js';
|
||||
import { Pipeline, type TryRewriteResult } from '../base-pipeline.js';
|
||||
import type { SinglePageBuiltModule } from '../build/types.js';
|
||||
export declare class AppPipeline extends Pipeline {
|
||||
#private;
|
||||
static create(manifestData: ManifestData, { logger, manifest, mode, renderers, resolve, serverLike, streaming, defaultRoutes, }: Pick<AppPipeline, 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming' | 'defaultRoutes'>): AppPipeline;
|
||||
static create({ logger, manifest, runtimeMode, renderers, resolve, serverLike, streaming, defaultRoutes, }: Pick<AppPipeline, 'logger' | 'manifest' | 'runtimeMode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming' | 'defaultRoutes'>): AppPipeline;
|
||||
headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'>;
|
||||
componentMetadata(): void;
|
||||
getComponentByRoute(routeData: RouteData): Promise<ComponentInstance>;
|
||||
|
11
node_modules/astro/dist/core/app/pipeline.js
generated
vendored
11
node_modules/astro/dist/core/app/pipeline.js
generated
vendored
@@ -3,11 +3,10 @@ import { RedirectSinglePageBuiltModule } from "../redirects/component.js";
|
||||
import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js";
|
||||
import { findRouteToRewrite } from "../routing/rewrite.js";
|
||||
class AppPipeline extends Pipeline {
|
||||
#manifestData;
|
||||
static create(manifestData, {
|
||||
static create({
|
||||
logger,
|
||||
manifest,
|
||||
mode,
|
||||
runtimeMode,
|
||||
renderers,
|
||||
resolve,
|
||||
serverLike,
|
||||
@@ -17,7 +16,7 @@ class AppPipeline extends Pipeline {
|
||||
const pipeline = new AppPipeline(
|
||||
logger,
|
||||
manifest,
|
||||
mode,
|
||||
runtimeMode,
|
||||
renderers,
|
||||
resolve,
|
||||
serverLike,
|
||||
@@ -32,7 +31,6 @@ class AppPipeline extends Pipeline {
|
||||
void 0,
|
||||
defaultRoutes
|
||||
);
|
||||
pipeline.#manifestData = manifestData;
|
||||
return pipeline;
|
||||
}
|
||||
headElements(routeData) {
|
||||
@@ -67,7 +65,8 @@ class AppPipeline extends Pipeline {
|
||||
routes: this.manifest?.routes.map((r) => r.routeData),
|
||||
trailingSlash: this.manifest.trailingSlash,
|
||||
buildFormat: this.manifest.buildFormat,
|
||||
base: this.manifest.base
|
||||
base: this.manifest.base,
|
||||
outDir: this.serverLike ? this.manifest.buildClientDir : this.manifest.outDir
|
||||
});
|
||||
const componentInstance = await this.getComponentByRoute(routeData);
|
||||
return { newUrl, pathname, componentInstance, routeData };
|
||||
|
55
node_modules/astro/dist/core/app/types.d.ts
generated
vendored
55
node_modules/astro/dist/core/app/types.d.ts
generated
vendored
@@ -1,7 +1,13 @@
|
||||
import type { AstroMiddlewareInstance, ComponentInstance, Locales, RouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult, SerializedRouteData } from '../../@types/astro.js';
|
||||
import type { ZodType } from 'zod';
|
||||
import type { ActionAccept, ActionClient } from '../../actions/runtime/virtual/server.js';
|
||||
import type { RoutingStrategies } from '../../i18n/utils.js';
|
||||
import type { ComponentInstance, SerializedRouteData } from '../../types/astro.js';
|
||||
import type { AstroMiddlewareInstance } from '../../types/public/common.js';
|
||||
import type { AstroConfig, CspAlgorithm, Locales, ResolvedSessionConfig } from '../../types/public/config.js';
|
||||
import type { RouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../types/public/internal.js';
|
||||
import type { SinglePageBuiltModule } from '../build/types.js';
|
||||
export type ComponentPath = string;
|
||||
import type { CspDirective } from '../csp/config.js';
|
||||
type ComponentPath = string;
|
||||
export type StylesheetAsset = {
|
||||
type: 'inline';
|
||||
content: string;
|
||||
@@ -25,7 +31,7 @@ export interface RouteInfo {
|
||||
export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
|
||||
routeData: SerializedRouteData;
|
||||
};
|
||||
export type ImportComponentInstance = () => Promise<SinglePageBuiltModule>;
|
||||
type ImportComponentInstance = () => Promise<SinglePageBuiltModule>;
|
||||
export type AssetsPrefix = string | ({
|
||||
fallback: string;
|
||||
} & Record<string, string>) | undefined;
|
||||
@@ -35,8 +41,15 @@ export type SSRManifest = {
|
||||
routes: RouteInfo[];
|
||||
site?: string;
|
||||
base: string;
|
||||
trailingSlash: 'always' | 'never' | 'ignore';
|
||||
buildFormat: 'file' | 'directory' | 'preserve';
|
||||
/**
|
||||
* The base of the assets generated **by the user**. For example, scripts created by the user falls under this category.
|
||||
*
|
||||
* The value of this field comes from `vite.base`. We aren't usually this tight to vite in our code base, so probably
|
||||
* this should be refactored somehow.
|
||||
*/
|
||||
userAssetsBase: string | undefined;
|
||||
trailingSlash: AstroConfig['trailingSlash'];
|
||||
buildFormat: NonNullable<AstroConfig['build']>['format'];
|
||||
compressHTML: boolean;
|
||||
assetsPrefix?: AssetsPrefix;
|
||||
renderers: SSRLoadedRenderer[];
|
||||
@@ -55,8 +68,19 @@ export type SSRManifest = {
|
||||
key: Promise<CryptoKey>;
|
||||
i18n: SSRManifestI18n | undefined;
|
||||
middleware?: () => Promise<AstroMiddlewareInstance> | AstroMiddlewareInstance;
|
||||
actions?: () => Promise<SSRActions> | SSRActions;
|
||||
checkOrigin: boolean;
|
||||
experimentalEnvGetSecretEnabled: boolean;
|
||||
sessionConfig?: ResolvedSessionConfig<any>;
|
||||
cacheDir: string | URL;
|
||||
srcDir: string | URL;
|
||||
outDir: string | URL;
|
||||
publicDir: string | URL;
|
||||
buildClientDir: string | URL;
|
||||
buildServerDir: string | URL;
|
||||
csp: SSRManifestCSP | undefined;
|
||||
};
|
||||
export type SSRActions = {
|
||||
server: Record<string, ActionClient<unknown, ActionAccept, ZodType>>;
|
||||
};
|
||||
export type SSRManifestI18n = {
|
||||
fallback: Record<string, string> | undefined;
|
||||
@@ -66,6 +90,17 @@ export type SSRManifestI18n = {
|
||||
defaultLocale: string;
|
||||
domainLookupTable: Record<string, string>;
|
||||
};
|
||||
export type SSRManifestCSP = {
|
||||
cspDestination: 'adapter' | 'meta' | 'header' | undefined;
|
||||
algorithm: CspAlgorithm;
|
||||
scriptHashes: string[];
|
||||
scriptResources: string[];
|
||||
isStrictDynamic: boolean;
|
||||
styleHashes: string[];
|
||||
styleResources: string[];
|
||||
directives: CspDirective[];
|
||||
};
|
||||
/** Public type exposed through the `astro:build:ssr` integration hook */
|
||||
export type SerializedSSRManifest = Omit<SSRManifest, 'middleware' | 'routes' | 'assets' | 'componentMetadata' | 'inlinedScripts' | 'clientDirectives' | 'serverIslandNameMap' | 'key'> & {
|
||||
routes: SerializedRouteInfo[];
|
||||
assets: string[];
|
||||
@@ -75,3 +110,11 @@ export type SerializedSSRManifest = Omit<SSRManifest, 'middleware' | 'routes' |
|
||||
serverIslandNameMap: [string, string][];
|
||||
key: string;
|
||||
};
|
||||
export type NodeAppHeadersJson = {
|
||||
pathname: string;
|
||||
headers: {
|
||||
key: string;
|
||||
value: string;
|
||||
}[];
|
||||
}[];
|
||||
export {};
|
||||
|
Reference in New Issue
Block a user