ssr-function.ts — astro Source File
Architecture documentation for ssr-function.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 9db13972_7aec_5732_70c9_a18fc4679303["ssr-function.ts"] 784aac79_cb80_513f_cc11_438b93b288c4["functions"] 9db13972_7aec_5732_70c9_a18fc4679303 --> 784aac79_cb80_513f_cc11_438b93b288c4 cb36772b_5ea4_3a79_49fa_b1570632623e["setup"] 9db13972_7aec_5732_70c9_a18fc4679303 --> cb36772b_5ea4_3a79_49fa_b1570632623e 628bf9d0_5c4b_0172_8f15_27d1874f22c6["virtual:astro-netlify:config"] 9db13972_7aec_5732_70c9_a18fc4679303 --> 628bf9d0_5c4b_0172_8f15_27d1874f22c6 e5e807ea_8b6a_956c_db61_84f6433ad893["entrypoint"] 9db13972_7aec_5732_70c9_a18fc4679303 --> e5e807ea_8b6a_956c_db61_84f6433ad893 style 9db13972_7aec_5732_70c9_a18fc4679303 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { Context } from '@netlify/functions';
import { setGetEnv } from 'astro/env/setup';
import { middlewareSecret, cacheOnDemandPages, packageVersion } from 'virtual:astro-netlify:config';
import { createApp } from 'astro/app/entrypoint';
setGetEnv((key) => process.env[key]);
const app = createApp();
export function createHandler({ notFoundContent }: { notFoundContent: string | undefined }) {
return async function handler(request: Request, context: Context): Promise<Response> {
const routeData = app.match(request);
if (!routeData && typeof notFoundContent !== 'undefined') {
return new Response(notFoundContent, {
status: 404,
headers: { 'Content-Type': 'text/html; charset=utf-8' },
});
}
let locals: Record<string, unknown> = {};
const astroLocalsHeader = request.headers.get('x-astro-locals');
const middlewareSecretHeader = request.headers.get('x-astro-middleware-secret');
if (astroLocalsHeader) {
if (middlewareSecretHeader !== middlewareSecret) {
return new Response('Forbidden', { status: 403 });
}
// hide the secret from the rest of user and library code
request.headers.delete('x-astro-middleware-secret');
locals = JSON.parse(astroLocalsHeader);
}
locals.netlify = { context };
const response = await app.render(request, {
routeData,
locals,
clientAddress: context.ip,
});
if (app.setCookieHeaders) {
for (const setCookieHeader of app.setCookieHeaders(response)) {
response.headers.append('Set-Cookie', setCookieHeader);
}
}
if (cacheOnDemandPages) {
const isCacheableMethod = ['GET', 'HEAD'].includes(request.method);
// any user-provided Cache-Control headers take precedence
const hasCacheControl = [
'Cache-Control',
'CDN-Cache-Control',
'Netlify-CDN-Cache-Control',
].some((header) => response.headers.has(header));
if (isCacheableMethod && !hasCacheControl) {
// caches this page for up to a year
response.headers.append('CDN-Cache-Control', 'public, max-age=31536000, must-revalidate');
}
}
return response;
};
}
export const config = {
includedFiles: ['**/*'],
name: 'Astro SSR',
nodeBundler: 'none',
generator: `@astrojs/netlify@${packageVersion}`,
path: '/*',
preferStatic: true,
};
Domain
Subdomains
Functions
Dependencies
- entrypoint
- functions
- setup
- virtual:astro-netlify:config
Source
Frequently Asked Questions
What does ssr-function.ts do?
ssr-function.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in ssr-function.ts?
ssr-function.ts defines 1 function(s): createHandler.
What does ssr-function.ts depend on?
ssr-function.ts imports 4 module(s): entrypoint, functions, setup, virtual:astro-netlify:config.
Where is ssr-function.ts in the architecture?
ssr-function.ts is located at packages/integrations/netlify/src/ssr-function.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/netlify/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free