middleware.js — astro Source File
Architecture documentation for middleware.js, a javascript file in the astro codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 66a5ef02_454b_899e_f367_20548926b8ee["middleware.js"] 3a7a7ff7_6c64_95f9_af85_4deb518834f1["astro:middleware"] 66a5ef02_454b_899e_f367_20548926b8ee --> 3a7a7ff7_6c64_95f9_af85_4deb518834f1 7b168a2c_1fab_3fd0_0ca6_b02ef3296495["middleware"] 66a5ef02_454b_899e_f367_20548926b8ee --> 7b168a2c_1fab_3fd0_0ca6_b02ef3296495 style 66a5ef02_454b_899e_f367_20548926b8ee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { sequence } from 'astro:middleware';
import {defineMiddleware} from "astro/middleware";
let contextReroute = false;
export const first = async (context, next) => {
if (context.url.pathname.includes('/auth')) {
}
return next();
};
export const second = async (context, next) => {
if (context.url.pathname.includes('/auth')) {
if (context.url.pathname.includes('/auth/dashboard')) {
contextReroute = true;
return await context.rewrite('/');
}
if (context.url.pathname.includes('/auth/base')) {
return await next('/');
}
if (context.url.pathname.includes('/auth/params')) {
return next('/?foo=bar');
}
if (context.url.pathname.includes('/auth/astro-params')) {
return next('/auth/1234');
}
}
return next();
};
export const third = defineMiddleware(async (context, next) => {
// just making sure that we are testing the change in context coming from `next()`
if (context.url.pathname.startsWith('/') && contextReroute === false) {
context.locals.auth = 'Third function called';
}
if (context.params?.id === '1234') {
context.locals.auth = 'Params changed'
}
return next();
});
export const onRequest = sequence(first, second, third);
Domain
Subdomains
Dependencies
- astro:middleware
- middleware
Source
Frequently Asked Questions
What does middleware.js do?
middleware.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain, SsrAdapters subdomain.
What functions are defined in middleware.js?
middleware.js defines 3 function(s): first, second, third.
What does middleware.js depend on?
middleware.js imports 2 module(s): astro:middleware, middleware.
Where is middleware.js in the architecture?
middleware.js is located at packages/astro/test/fixtures/reroute/src/middleware.js (domain: IntegrationAdapters, subdomain: SsrAdapters, directory: packages/astro/test/fixtures/reroute/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free