Home / File/ entrypoint.ts — astro Source File

entrypoint.ts — astro Source File

Architecture documentation for entrypoint.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  888c71eb_1227_93b2_edd4_456430022b2c["entrypoint.ts"]
  094e8b99_b744_500d_30af_8edfef4c4276["../index.js"]
  888c71eb_1227_93b2_edd4_456430022b2c --> 094e8b99_b744_500d_30af_8edfef4c4276
  cb36772b_5ea4_3a79_49fa_b1570632623e["setup"]
  888c71eb_1227_93b2_edd4_456430022b2c --> cb36772b_5ea4_3a79_49fa_b1570632623e
  eb179da5_6bbe_8b1f_26c8_9345d6c75014["virtual:astro-vercel:config"]
  888c71eb_1227_93b2_edd4_456430022b2c --> eb179da5_6bbe_8b1f_26c8_9345d6c75014
  e5e807ea_8b6a_956c_db61_84f6433ad893["entrypoint"]
  888c71eb_1227_93b2_edd4_456430022b2c --> e5e807ea_8b6a_956c_db61_84f6433ad893
  style 888c71eb_1227_93b2_edd4_456430022b2c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { setGetEnv } from 'astro/env/setup';
import {
	ASTRO_LOCALS_HEADER,
	ASTRO_MIDDLEWARE_SECRET_HEADER,
	ASTRO_PATH_HEADER,
	ASTRO_PATH_PARAM,
} from '../index.js';
import { middlewareSecret, skewProtection } from 'virtual:astro-vercel:config';
import { createApp } from 'astro/app/entrypoint';

setGetEnv((key) => process.env[key]);

const app = createApp();

export default {
	async fetch(request: Request): Promise<Response> {
		const url = new URL(request.url);
		const realPath =
			request.headers.get(ASTRO_PATH_HEADER) ?? url.searchParams.get(ASTRO_PATH_PARAM);
		if (typeof realPath === 'string') {
			url.pathname = realPath;
			request = new Request(url.toString(), {
				method: request.method,
				headers: request.headers,
				body: request.body,
			});
		}

		const routeData = app.match(request);

		let locals: Record<string, unknown> = {};

		const astroLocalsHeader = request.headers.get(ASTRO_LOCALS_HEADER);
		const middlewareSecretHeader = request.headers.get(ASTRO_MIDDLEWARE_SECRET_HEADER);
		if (astroLocalsHeader) {
			if (middlewareSecretHeader !== middlewareSecret) {
				return new Response('Forbidden', { status: 403 });
			}
			// hide the secret from the rest of user code
			request.headers.delete(ASTRO_MIDDLEWARE_SECRET_HEADER);
			locals = JSON.parse(astroLocalsHeader);
		}

		// https://vercel.com/docs/deployments/skew-protection#supported-frameworks
		if (skewProtection && process.env.VERCEL_SKEW_PROTECTION_ENABLED === '1') {
			request.headers.set('x-deployment-id', process.env.VERCEL_DEPLOYMENT_ID!);
		}

		const response = await app.render(request, {
			routeData,
			clientAddress: request.headers.get('x-forwarded-for') ?? undefined,
			locals,
		});

		if (app.setCookieHeaders) {
			for (const setCookieHeader of app.setCookieHeaders(response)) {
				response.headers.append('Set-Cookie', setCookieHeader);
			}
		}

		return response;
	},
};

Domain

Subdomains

Functions

Dependencies

  • ../index.js
  • entrypoint
  • setup
  • virtual:astro-vercel:config

Frequently Asked Questions

What does entrypoint.ts do?
entrypoint.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in entrypoint.ts?
entrypoint.ts defines 1 function(s): default.fetch.
What does entrypoint.ts depend on?
entrypoint.ts imports 4 module(s): ../index.js, entrypoint, setup, virtual:astro-vercel:config.
Where is entrypoint.ts in the architecture?
entrypoint.ts is located at packages/integrations/vercel/src/serverless/entrypoint.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/integrations/vercel/src/serverless).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free