full site update
This commit is contained in:
3
node_modules/astro/dist/core/middleware/callMiddleware.d.ts
generated
vendored
3
node_modules/astro/dist/core/middleware/callMiddleware.d.ts
generated
vendored
@@ -1,4 +1,5 @@
|
||||
import type { APIContext, MiddlewareHandler, RewritePayload } from '../../@types/astro.js';
|
||||
import type { MiddlewareHandler, RewritePayload } from '../../types/public/common.js';
|
||||
import type { APIContext } from '../../types/public/context.js';
|
||||
/**
|
||||
* Utility function that is in charge of calling the middleware.
|
||||
*
|
||||
|
9
node_modules/astro/dist/core/middleware/index.d.ts
generated
vendored
9
node_modules/astro/dist/core/middleware/index.d.ts
generated
vendored
@@ -1,4 +1,5 @@
|
||||
import type { APIContext, MiddlewareHandler, Params } from '../../@types/astro.js';
|
||||
import type { MiddlewareHandler, Params } from '../../types/public/common.js';
|
||||
import type { APIContext } from '../../types/public/context.js';
|
||||
import { sequence } from './sequence.js';
|
||||
declare function defineMiddleware(fn: MiddlewareHandler): MiddlewareHandler;
|
||||
/**
|
||||
@@ -21,11 +22,15 @@ export type CreateContext = {
|
||||
* User defined default locale
|
||||
*/
|
||||
defaultLocale: string;
|
||||
/**
|
||||
* Initial value of the locals
|
||||
*/
|
||||
locals: App.Locals;
|
||||
};
|
||||
/**
|
||||
* Creates a context to be passed to Astro middleware `onRequest` function.
|
||||
*/
|
||||
declare function createContext({ request, params, userDefinedLocales, defaultLocale, }: CreateContext): APIContext;
|
||||
declare function createContext({ request, params, userDefinedLocales, defaultLocale, locals, }: CreateContext): APIContext;
|
||||
/**
|
||||
* It attempts to serialize `value` and return it as a string.
|
||||
*
|
||||
|
39
node_modules/astro/dist/core/middleware/index.js
generated
vendored
39
node_modules/astro/dist/core/middleware/index.js
generated
vendored
@@ -4,10 +4,11 @@ import {
|
||||
computePreferredLocale,
|
||||
computePreferredLocaleList
|
||||
} from "../../i18n/utils.js";
|
||||
import { ASTRO_VERSION, clientAddressSymbol, clientLocalsSymbol } from "../constants.js";
|
||||
import { ASTRO_VERSION, clientLocalsSymbol } from "../constants.js";
|
||||
import { AstroCookies } from "../cookies/index.js";
|
||||
import { AstroError, AstroErrorData } from "../errors/index.js";
|
||||
import { getClientIpAddress } from "../routing/request.js";
|
||||
import { getOriginPathname } from "../routing/rewrite.js";
|
||||
import { sequence } from "./sequence.js";
|
||||
function defineMiddleware(fn) {
|
||||
return fn;
|
||||
@@ -16,7 +17,8 @@ function createContext({
|
||||
request,
|
||||
params = {},
|
||||
userDefinedLocales = [],
|
||||
defaultLocale = ""
|
||||
defaultLocale = "",
|
||||
locals
|
||||
}) {
|
||||
let preferredLocale = void 0;
|
||||
let preferredLocaleList = void 0;
|
||||
@@ -35,6 +37,7 @@ function createContext({
|
||||
generator: `Astro v${ASTRO_VERSION}`,
|
||||
props: {},
|
||||
rewrite,
|
||||
routePattern: "",
|
||||
redirect(path, status) {
|
||||
return new Response(null, {
|
||||
status: status || 302,
|
||||
@@ -43,6 +46,7 @@ function createContext({
|
||||
}
|
||||
});
|
||||
},
|
||||
isPrerendered: false,
|
||||
get preferredLocale() {
|
||||
return preferredLocale ??= computePreferredLocale(request, userDefinedLocales);
|
||||
},
|
||||
@@ -53,6 +57,9 @@ function createContext({
|
||||
return currentLocale ??= computeCurrentLocale(route, userDefinedLocales, defaultLocale);
|
||||
},
|
||||
url,
|
||||
get originPathname() {
|
||||
return getOriginPathname(request);
|
||||
},
|
||||
get clientAddress() {
|
||||
if (clientIpAddress) {
|
||||
return clientIpAddress;
|
||||
@@ -64,23 +71,27 @@ function createContext({
|
||||
return clientIpAddress;
|
||||
},
|
||||
get locals() {
|
||||
let locals = Reflect.get(request, clientLocalsSymbol);
|
||||
let _locals = locals ?? Reflect.get(request, clientLocalsSymbol);
|
||||
if (locals === void 0) {
|
||||
locals = {};
|
||||
Reflect.set(request, clientLocalsSymbol, locals);
|
||||
_locals = {};
|
||||
}
|
||||
if (typeof locals !== "object") {
|
||||
if (typeof _locals !== "object") {
|
||||
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
||||
}
|
||||
return locals;
|
||||
return _locals;
|
||||
},
|
||||
// We define a custom property, so we can check the value passed to locals
|
||||
set locals(val) {
|
||||
if (typeof val !== "object") {
|
||||
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
||||
} else {
|
||||
Reflect.set(request, clientLocalsSymbol, val);
|
||||
}
|
||||
set locals(_) {
|
||||
throw new AstroError(AstroErrorData.LocalsReassigned);
|
||||
},
|
||||
insertDirective() {
|
||||
},
|
||||
insertScriptResource() {
|
||||
},
|
||||
insertStyleResource() {
|
||||
},
|
||||
insertScriptHash() {
|
||||
},
|
||||
insertStyleHash() {
|
||||
}
|
||||
};
|
||||
return Object.assign(context, {
|
||||
|
2
node_modules/astro/dist/core/middleware/noop-middleware.d.ts
generated
vendored
2
node_modules/astro/dist/core/middleware/noop-middleware.d.ts
generated
vendored
@@ -1,2 +1,2 @@
|
||||
import type { MiddlewareHandler } from '../../@types/astro.js';
|
||||
import type { MiddlewareHandler } from '../../types/public/common.js';
|
||||
export declare const NOOP_MIDDLEWARE_FN: MiddlewareHandler;
|
||||
|
2
node_modules/astro/dist/core/middleware/sequence.d.ts
generated
vendored
2
node_modules/astro/dist/core/middleware/sequence.d.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import type { MiddlewareHandler } from '../../@types/astro.js';
|
||||
import type { MiddlewareHandler } from '../../types/public/common.js';
|
||||
/**
|
||||
*
|
||||
* It accepts one or more middleware handlers and makes sure that they are run in sequence.
|
||||
|
27
node_modules/astro/dist/core/middleware/sequence.js
generated
vendored
27
node_modules/astro/dist/core/middleware/sequence.js
generated
vendored
@@ -1,6 +1,9 @@
|
||||
import { AstroCookies } from "../cookies/cookies.js";
|
||||
import { apiContextRoutesSymbol } from "../render-context.js";
|
||||
import { ForbiddenRewrite } from "../errors/errors-data.js";
|
||||
import { AstroError } from "../errors/index.js";
|
||||
import { getParams } from "../render/index.js";
|
||||
import { apiContextRoutesSymbol } from "../render-context.js";
|
||||
import { setOriginPathname } from "../routing/rewrite.js";
|
||||
import { defineMiddleware } from "./index.js";
|
||||
function sequence(...handlers) {
|
||||
const filtered = handlers.filter((h) => !!h);
|
||||
@@ -22,23 +25,41 @@ function sequence(...handlers) {
|
||||
if (payload instanceof Request) {
|
||||
newRequest = payload;
|
||||
} else if (payload instanceof URL) {
|
||||
newRequest = new Request(payload, handleContext.request);
|
||||
newRequest = new Request(payload, handleContext.request.clone());
|
||||
} else {
|
||||
newRequest = new Request(
|
||||
new URL(payload, handleContext.url.origin),
|
||||
handleContext.request
|
||||
handleContext.request.clone()
|
||||
);
|
||||
}
|
||||
const oldPathname = handleContext.url.pathname;
|
||||
const pipeline = Reflect.get(handleContext, apiContextRoutesSymbol);
|
||||
const { routeData, pathname } = await pipeline.tryRewrite(
|
||||
payload,
|
||||
handleContext.request
|
||||
);
|
||||
if (pipeline.serverLike === true && handleContext.isPrerendered === false && routeData.prerender === true) {
|
||||
throw new AstroError({
|
||||
...ForbiddenRewrite,
|
||||
message: ForbiddenRewrite.message(
|
||||
handleContext.url.pathname,
|
||||
pathname,
|
||||
routeData.component
|
||||
),
|
||||
hint: ForbiddenRewrite.hint(routeData.component)
|
||||
});
|
||||
}
|
||||
carriedPayload = payload;
|
||||
handleContext.request = newRequest;
|
||||
handleContext.url = new URL(newRequest.url);
|
||||
handleContext.cookies = new AstroCookies(newRequest);
|
||||
handleContext.params = getParams(routeData, pathname);
|
||||
setOriginPathname(
|
||||
handleContext.request,
|
||||
oldPathname,
|
||||
pipeline.manifest.trailingSlash,
|
||||
pipeline.manifest.buildFormat
|
||||
);
|
||||
}
|
||||
return applyHandle(i + 1, handleContext);
|
||||
} else {
|
||||
|
2
node_modules/astro/dist/core/middleware/vite-plugin.d.ts
generated
vendored
2
node_modules/astro/dist/core/middleware/vite-plugin.d.ts
generated
vendored
@@ -1,5 +1,5 @@
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import type { AstroSettings } from '../../@types/astro.js';
|
||||
import type { AstroSettings } from '../../types/astro.js';
|
||||
import type { BuildInternals } from '../build/internal.js';
|
||||
import type { StaticBuildOptions } from '../build/types.js';
|
||||
export declare const MIDDLEWARE_MODULE_ID = "\0astro-internal:middleware";
|
||||
|
12
node_modules/astro/dist/core/middleware/vite-plugin.js
generated
vendored
12
node_modules/astro/dist/core/middleware/vite-plugin.js
generated
vendored
@@ -1,9 +1,9 @@
|
||||
import { normalizePath } from "vite";
|
||||
import { getOutputDirectory } from "../../prerender/utils.js";
|
||||
import { getServerOutputDirectory } from "../../prerender/utils.js";
|
||||
import { addRollupInput } from "../build/add-rollup-input.js";
|
||||
import { MIDDLEWARE_PATH_SEGMENT_NAME } from "../constants.js";
|
||||
import { MissingMiddlewareForInternationalization } from "../errors/errors-data.js";
|
||||
import { AstroError } from "../errors/index.js";
|
||||
import { normalizePath } from "../viteUtils.js";
|
||||
const MIDDLEWARE_MODULE_ID = "\0astro-internal:middleware";
|
||||
const NOOP_MIDDLEWARE = "\0noop-middleware";
|
||||
function vitePluginMiddleware({ settings }) {
|
||||
@@ -36,14 +36,14 @@ function vitePluginMiddleware({ settings }) {
|
||||
if (!userMiddlewareIsPresent && settings.config.i18n?.routing === "manual") {
|
||||
throw new AstroError(MissingMiddlewareForInternationalization);
|
||||
}
|
||||
return "export const onRequest = (_, next) => next()";
|
||||
return { code: "export const onRequest = (_, next) => next()" };
|
||||
} else if (id === MIDDLEWARE_MODULE_ID) {
|
||||
if (!userMiddlewareIsPresent && settings.config.i18n?.routing === "manual") {
|
||||
throw new AstroError(MissingMiddlewareForInternationalization);
|
||||
}
|
||||
const preMiddleware = createMiddlewareImports(settings.middlewares.pre, "pre");
|
||||
const postMiddleware = createMiddlewareImports(settings.middlewares.post, "post");
|
||||
const source = `
|
||||
const code = `
|
||||
${userMiddlewareIsPresent ? `import { onRequest as userOnRequest } from '${resolvedMiddlewareId}';` : ""}
|
||||
import { sequence } from 'astro:middleware';
|
||||
${preMiddleware.importsCode}${postMiddleware.importsCode}
|
||||
@@ -54,7 +54,7 @@ export const onRequest = sequence(
|
||||
${postMiddleware.sequenceCode}
|
||||
);
|
||||
`.trim();
|
||||
return source;
|
||||
return { code };
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -84,7 +84,7 @@ function vitePluginMiddlewareBuild(opts, internals) {
|
||||
writeBundle(_, bundle) {
|
||||
for (const [chunkName, chunk] of Object.entries(bundle)) {
|
||||
if (chunk.type !== "asset" && chunk.facadeModuleId === MIDDLEWARE_MODULE_ID) {
|
||||
const outputDirectory = getOutputDirectory(opts.settings.config);
|
||||
const outputDirectory = getServerOutputDirectory(opts.settings);
|
||||
internals.middlewareEntryPoint = new URL(chunkName, outputDirectory);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user