renderCspContent() — astro Function Reference
Architecture documentation for the renderCspContent() function in csp.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD fe922916_daa1_747c_aa68_01cf1cf18a9f["renderCspContent()"] 678da59a_6955_fac5_4ead_acfc331bfdcc["csp.ts"] fe922916_daa1_747c_aa68_01cf1cf18a9f -->|defined in| 678da59a_6955_fac5_4ead_acfc331bfdcc style fe922916_daa1_747c_aa68_01cf1cf18a9f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/runtime/server/render/csp.ts lines 3–42
export function renderCspContent(result: SSRResult): string {
const finalScriptHashes = new Set();
const finalStyleHashes = new Set();
for (const scriptHash of result.scriptHashes) {
finalScriptHashes.add(`'${scriptHash}'`);
}
for (const styleHash of result.styleHashes) {
finalStyleHashes.add(`'${styleHash}'`);
}
for (const styleHash of result._metadata.extraStyleHashes) {
finalStyleHashes.add(`'${styleHash}'`);
}
for (const scriptHash of result._metadata.extraScriptHashes) {
finalScriptHashes.add(`'${scriptHash}'`);
}
let directives;
if (result.directives.length > 0) {
directives = result.directives.join(';') + ';';
}
let scriptResources = "'self'";
if (result.scriptResources.length > 0) {
scriptResources = result.scriptResources.map((r) => `${r}`).join(' ');
}
let styleResources = "'self'";
if (result.styleResources.length > 0) {
styleResources = result.styleResources.map((r) => `${r}`).join(' ');
}
const strictDynamic = result.isStrictDynamic ? ` 'strict-dynamic'` : '';
const scriptSrc = `script-src ${scriptResources} ${Array.from(finalScriptHashes).join(' ')}${strictDynamic};`;
const styleSrc = `style-src ${styleResources} ${Array.from(finalStyleHashes).join(' ')};`;
return [directives, scriptSrc, styleSrc].filter(Boolean).join(' ');
}
Domain
Subdomains
Source
Frequently Asked Questions
What does renderCspContent() do?
renderCspContent() is a function in the astro codebase, defined in packages/astro/src/runtime/server/render/csp.ts.
Where is renderCspContent() defined?
renderCspContent() is defined in packages/astro/src/runtime/server/render/csp.ts at line 3.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free