32 lines
964 B
TypeScript
32 lines
964 B
TypeScript
// CSP 설정을 위한 환경별 구성 (img-src만)
|
|
export const CSP_CONFIG = {
|
|
development: {
|
|
"img-src": ["'self'", "data:", "https:", "blob:", "http://localhost:*"]
|
|
},
|
|
production: {
|
|
"img-src": ["'self'", "data:", "https:", "blob:"]
|
|
}
|
|
};
|
|
|
|
// CSP 헤더 값을 생성하는 함수
|
|
export function generateCSPHeader(environment: 'development' | 'production' = 'development'): string {
|
|
const config = CSP_CONFIG[environment];
|
|
|
|
return Object.entries(config)
|
|
.map(([key, values]) => {
|
|
return `${key} ${values.join(' ')}`;
|
|
})
|
|
.join('; ');
|
|
}
|
|
|
|
// img-src에 특정 도메인 추가하는 함수
|
|
export function addImageDomain(domain: string, environment: 'development' | 'production' = 'development'): string {
|
|
const config = CSP_CONFIG[environment];
|
|
const currentImgSrc = config["img-src"];
|
|
|
|
if (!currentImgSrc.includes(domain)) {
|
|
currentImgSrc.push(domain);
|
|
}
|
|
|
|
return `img-src ${currentImgSrc.join(' ')};`;
|
|
}
|