Home / Function/ getDirectives() — astro Function Reference

getDirectives() — astro Function Reference

Architecture documentation for the getDirectives() function in common.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  419df8c0_7d2b_f293_b78a_e4f14b33f089["getDirectives()"]
  0f62fcfb_9504_86a2_16bb_d8a9742e1f23["common.ts"]
  419df8c0_7d2b_f293_b78a_e4f14b33f089 -->|defined in| 0f62fcfb_9504_86a2_16bb_d8a9742e1f23
  d741c4df_8356_df8d_9ff4_08ee984fdead["shouldTrackCspHashes()"]
  419df8c0_7d2b_f293_b78a_e4f14b33f089 -->|calls| d741c4df_8356_df8d_9ff4_08ee984fdead
  style 419df8c0_7d2b_f293_b78a_e4f14b33f089 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/csp/common.ts lines 57–87

export function getDirectives(settings: AstroSettings): CspDirective[] {
	const { csp } = settings.config.security;
	if (!shouldTrackCspHashes(csp)) {
		return [];
	}
	const userDirectives = csp === true ? [] : [...(csp.directives ?? [])];
	const fontResources = Array.from(settings.injectedCsp.fontResources.values());

	if (fontResources.length === 0) {
		// If no font resources, just return user directives
		return userDirectives;
	}

	const fontSrcIndex = userDirectives.findIndex((e) => e.startsWith('font-src'));
	if (fontSrcIndex === -1) {
		// Add new font-src directive
		return [...userDirectives, `font-src ${fontResources.join(' ')}`];
	}

	// Merge and deduplicate font-src resources
	const existing = userDirectives[fontSrcIndex]
		// split spaces
		.split(/\s+/)
		// ignore first match as it's the directive name
		.slice(1)
		// Avoid duplicated spaces
		.filter(Boolean);
	const merged = Array.from(new Set([...existing, ...fontResources]));
	userDirectives[fontSrcIndex] = `font-src ${merged.join(' ')}`;
	return userDirectives;
}

Domain

Subdomains

Frequently Asked Questions

What does getDirectives() do?
getDirectives() is a function in the astro codebase, defined in packages/astro/src/core/csp/common.ts.
Where is getDirectives() defined?
getDirectives() is defined in packages/astro/src/core/csp/common.ts at line 57.
What does getDirectives() call?
getDirectives() calls 1 function(s): shouldTrackCspHashes.

Analyze Your Own Codebase

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

Try Supermodel Free