Home / File/ image-endpoint.ts — astro Source File

image-endpoint.ts — astro Source File

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

File typescript CoreAstro RoutingSystem 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  8b4ba749_e2c7_52bd_0100_37c345e7790d["image-endpoint.ts"]
  f6b816b8_cbf1_258a_b6ec_69418ae629ce["astro:assets"]
  8b4ba749_e2c7_52bd_0100_37c345e7790d --> f6b816b8_cbf1_258a_b6ec_69418ae629ce
  e4df8f29_fb2f_3d70_a962_fdf6a3670b22["path"]
  8b4ba749_e2c7_52bd_0100_37c345e7790d --> e4df8f29_fb2f_3d70_a962_fdf6a3670b22
  21f9daf1_9979_0313_afee_bbb8465c9f69["remote"]
  8b4ba749_e2c7_52bd_0100_37c345e7790d --> 21f9daf1_9979_0313_afee_bbb8465c9f69
  f16d8c76_2866_6150_bd14_0347b59abfe9["astro"]
  8b4ba749_e2c7_52bd_0100_37c345e7790d --> f16d8c76_2866_6150_bd14_0347b59abfe9
  style 8b4ba749_e2c7_52bd_0100_37c345e7790d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { imageConfig } from 'astro:assets';
import { isRemotePath } from '@astrojs/internal-helpers/path';
import { isRemoteAllowed } from '@astrojs/internal-helpers/remote';
import type { APIRoute } from 'astro';

export const prerender = false;

export const GET: APIRoute = (ctx) => {
	const href = ctx.url.searchParams.get('href');
	if (!href) {
		return new Response("Missing 'href' query parameter", {
			status: 400,
			statusText: "Missing 'href' query parameter",
		});
	}

	if (isRemotePath(href)) {
		if (isRemoteAllowed(href, imageConfig) === false) {
			return new Response('Forbidden', { status: 403 });
		} else {
			// Redirect here because it is safer than a proxy, remote image will be served by remote domain and not own domain
			return Response.redirect(href, 302);
		}
	}

	const proxied = new URL(href, ctx.url.origin);
	// Have we been tricked into thinking this is local?
	if (proxied.origin !== ctx.url.origin) {
		return new Response('Forbidden', { status: 403 });
	}

	return fetch(proxied);
};

Domain

Subdomains

Functions

Dependencies

  • astro
  • astro:assets
  • path
  • remote

Frequently Asked Questions

What does image-endpoint.ts do?
image-endpoint.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 image-endpoint.ts?
image-endpoint.ts defines 1 function(s): GET.
What does image-endpoint.ts depend on?
image-endpoint.ts imports 4 module(s): astro, astro:assets, path, remote.
Where is image-endpoint.ts in the architecture?
image-endpoint.ts is located at packages/integrations/cloudflare/src/entrypoints/image-endpoint.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/cloudflare/src/entrypoints).

Analyze Your Own Codebase

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

Try Supermodel Free