middleware.ts — astro Source File
Architecture documentation for middleware.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 67028c0d_9e9d_0a3c_6481_1f8d3d7ffb11["middleware.ts"] 3a7a7ff7_6c64_95f9_af85_4deb518834f1["astro:middleware"] 67028c0d_9e9d_0a3c_6481_1f8d3d7ffb11 --> 3a7a7ff7_6c64_95f9_af85_4deb518834f1 58a2600d_f5df_9651_e0d8_9010ddeef24d["astro:actions"] 67028c0d_9e9d_0a3c_6481_1f8d3d7ffb11 --> 58a2600d_f5df_9651_e0d8_9010ddeef24d style 67028c0d_9e9d_0a3c_6481_1f8d3d7ffb11 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { defineMiddleware } from 'astro:middleware';
import { getActionContext } from 'astro:actions';
const actionCookieForwarding = defineMiddleware(async (ctx, next) => {
if (ctx.isPrerendered) return next();
const { action, setActionResult, serializeActionResult } = getActionContext(ctx);
const payload = ctx.cookies.get('ACTION_PAYLOAD');
if (payload) {
const { actionName, actionResult } = payload.json();
setActionResult(actionName, actionResult);
ctx.cookies.delete('ACTION_PAYLOAD');
return next();
}
if (action?.calledFrom === 'form' && ctx.url.searchParams.has('actionCookieForwarding')) {
const actionResult = await action.handler();
ctx.cookies.set('ACTION_PAYLOAD', {
actionName: action.name,
actionResult: serializeActionResult(actionResult),
});
if (actionResult.error) {
const referer = ctx.request.headers.get('Referer');
if (!referer) {
throw new Error('Internal: Referer unexpectedly missing from Action POST request.');
}
return ctx.redirect(referer);
}
return ctx.redirect(ctx.originPathname);
}
return next();
});
export const onRequest = actionCookieForwarding;
Domain
Subdomains
Functions
Dependencies
- astro:actions
- astro:middleware
Source
Frequently Asked Questions
What does middleware.ts do?
middleware.ts is a source file in the astro codebase, written in typescript. It belongs to the E2ETesting domain, TestFixtures subdomain.
What functions are defined in middleware.ts?
middleware.ts defines 1 function(s): actionCookieForwarding.
What does middleware.ts depend on?
middleware.ts imports 2 module(s): astro:actions, astro:middleware.
Where is middleware.ts in the architecture?
middleware.ts is located at packages/astro/e2e/fixtures/actions-blog/src/middleware.ts (domain: E2ETesting, subdomain: TestFixtures, directory: packages/astro/e2e/fixtures/actions-blog/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free