2023-07-05 10:45:58 -05:00
|
|
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
|
2023-07-12 02:06:08 -05:00
|
|
|
exports[`Middleware with handler file 1`] = `
|
|
|
|
"// test/fixtures/middleware-with-edge-file/src/vercel-edge-middleware.js
|
2023-07-05 10:45:58 -05:00
|
|
|
function vercel_edge_middleware_default({ request, context }) {
|
|
|
|
return {
|
|
|
|
title: \\"Hello world\\"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-12 02:06:08 -05:00
|
|
|
// test/fixtures/middleware-with-edge-file/dist/middleware2.mjs
|
2023-07-05 10:45:58 -05:00
|
|
|
var onRequest = async (context, next) => {
|
|
|
|
const response = await next();
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
|
|
|
|
// <stdin>
|
|
|
|
import { createContext, trySerializeLocals } from \\"astro/middleware\\";
|
|
|
|
async function middleware(request, context) {
|
|
|
|
const url = new URL(request.url);
|
|
|
|
const ctx = createContext({
|
|
|
|
request,
|
|
|
|
params: {}
|
|
|
|
});
|
|
|
|
ctx.locals = vercel_edge_middleware_default({ request, context });
|
|
|
|
const next = async () => {
|
|
|
|
const response = await fetch(url, {
|
|
|
|
headers: {
|
|
|
|
\\"x-astro-locals\\": trySerializeLocals(ctx.locals)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
return onRequest(ctx, next);
|
|
|
|
}
|
|
|
|
export {
|
|
|
|
middleware as default
|
|
|
|
};
|
|
|
|
"
|
|
|
|
`;
|
2023-07-12 02:06:08 -05:00
|
|
|
|
|
|
|
exports[`Middleware without handler file 1`] = `
|
|
|
|
"// test/fixtures/middleware-without-edge-file/dist/middleware2.mjs
|
|
|
|
var onRequest = async (context, next) => {
|
|
|
|
const response = await next();
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
|
|
|
|
// <stdin>
|
|
|
|
import { createContext, trySerializeLocals } from \\"astro/middleware\\";
|
|
|
|
async function middleware(request, context) {
|
|
|
|
const url = new URL(request.url);
|
|
|
|
const ctx = createContext({
|
|
|
|
request,
|
|
|
|
params: {}
|
|
|
|
});
|
|
|
|
ctx.locals = {};
|
|
|
|
const next = async () => {
|
|
|
|
const response = await fetch(url, {
|
|
|
|
headers: {
|
|
|
|
\\"x-astro-locals\\": trySerializeLocals(ctx.locals)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return response;
|
|
|
|
};
|
|
|
|
return onRequest(ctx, next);
|
|
|
|
}
|
|
|
|
export {
|
|
|
|
middleware as default
|
|
|
|
};
|
|
|
|
"
|
|
|
|
`;
|