Files
classroomio/apps/dashboard/svelte.config.js
T

105 lines
4.0 KiB
JavaScript
Raw Normal View History

import 'dotenv/config';
import adapterNode from '@sveltejs/adapter-node';
2026-04-27 11:40:38 +01:00
import { getCspDomains } from './src/lib/utils/csp-domains.js';
2024-02-29 06:32:40 +00:00
import path from 'path';
2025-11-01 15:49:29 +01:00
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
const IS_CLOUDFLARE = process.env.CI_ENVIRONMENT === 'cloudflare';
2026-03-09 11:18:22 +01:00
2026-03-17 06:29:04 +01:00
const adapterCloudflare = IS_CLOUDFLARE ? (await import('@sveltejs/adapter-cloudflare')).default : null;
const isSelfHosted = process.env.PUBLIC_IS_SELFHOSTED === 'true';
2026-03-18 23:39:12 +01:00
const csp = getCspDomains(isSelfHosted, process.env.PUBLIC_SERVER_URL);
2024-09-23 01:21:05 +01:00
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [vitePreprocess({})],
kit: {
// Default: Node server (Render, Docker). Opt into Cloudflare Pages only when CI_ENVIRONMENT=cloudflare.
adapter: IS_CLOUDFLARE ? adapterCloudflare() : adapterNode(),
2024-02-29 06:32:40 +00:00
alias: {
$lib: path.resolve('./src/lib'),
$features: path.resolve('./src/lib/features'),
2025-11-01 16:18:29 +01:00
$mail: path.resolve('./src/mail'),
'$src/tools': path.resolve('./node_modules/@cio/ui/src/tools/index.ts'),
'$src/base/*': path.resolve('./node_modules/@cio/ui/src/base/*'),
'@cio/ui': path.resolve('./node_modules/@cio/ui/src'),
'@cio/ui/*': path.resolve('./node_modules/@cio/ui/src/*'),
'@cio/api': path.resolve('./node_modules/@cio/api/dist'),
'@cio/api/*': path.resolve('./node_modules/@cio/api/dist/*'),
'@cio/utils': path.resolve('./node_modules/@cio/utils/dist'),
'@cio/utils/*': path.resolve('./node_modules/@cio/utils/dist/*'),
'@cio/db/types': path.resolve('./node_modules/@cio/db/src/types.ts')
2025-12-03 09:33:53 +01:00
},
csp: {
2026-03-09 11:18:22 +01:00
mode: 'auto',
2025-12-03 09:33:53 +01:00
directives: {
'default-src': ['self'],
2026-03-18 23:39:12 +01:00
'script-src': ['self', ...csp.scriptSrc, 'unsafe-hashes', 'unsafe-eval'],
'style-src': ['self', 'unsafe-inline', ...csp.styleSrc],
'style-src-elem': ['self', 'unsafe-inline', ...csp.styleSrc],
// data: covers inlined woff2 (e.g. PDF.js / icon fonts); file fonts use 'self'
'font-src': ['self', 'data:', ...csp.fontSrc],
2026-03-18 23:39:12 +01:00
'img-src': ['self', 'data:', ...csp.mediaSrc, 'blob:', 'http://localhost:9000'],
'media-src': [
'self',
...csp.mediaSrc,
'data:',
'blob:',
'http://localhost:9000',
...(csp.apiOrigin ? [csp.apiOrigin] : [])
],
2026-03-18 23:39:12 +01:00
'frame-src': ['self', ...csp.frameSrc],
2025-12-03 09:33:53 +01:00
'connect-src': [
'self',
2026-03-09 11:18:22 +01:00
'blob:',
2025-12-25 05:09:27 +01:00
'http://localhost:3002',
2026-03-09 11:18:22 +01:00
'http://localhost:9000',
2026-03-18 23:39:12 +01:00
...(csp.apiOrigin ? [csp.apiOrigin] : []),
...csp.connectSrc
2025-12-03 09:33:53 +01:00
],
'worker-src': ['self', 'blob:'],
2025-12-03 09:33:53 +01:00
'object-src': ['none'],
'base-uri': ['self'],
'form-action': ['self'],
2026-04-27 11:40:38 +01:00
// 'self' allows same-origin iframes (e.g. widget preview at /widget-preview). 'none' blocks all embedding.
'frame-ancestors': ['self'],
2025-12-03 09:33:53 +01:00
'upgrade-insecure-requests': true
},
reportOnly: {
'default-src': ['self'],
2026-03-18 23:39:12 +01:00
'script-src': ['self', ...csp.scriptSrc, 'unsafe-hashes', 'unsafe-eval'],
'style-src': ['self', 'unsafe-inline', ...csp.styleSrc],
'style-src-elem': ['self', 'unsafe-inline', ...csp.styleSrc],
'font-src': ['self', 'data:', ...csp.fontSrc],
2026-03-18 23:39:12 +01:00
'img-src': ['self', 'data:', ...csp.mediaSrc, 'blob:', 'http://localhost:9000'],
'media-src': [
'self',
...csp.mediaSrc,
'data:',
'blob:',
'http://localhost:9000',
...(csp.apiOrigin ? [csp.apiOrigin] : [])
],
2026-03-18 23:39:12 +01:00
'frame-src': ['self', ...csp.frameSrc],
2025-12-03 09:33:53 +01:00
'connect-src': [
'self',
2026-03-09 11:18:22 +01:00
'blob:',
2025-12-25 05:09:27 +01:00
'http://localhost:3002',
2026-03-09 11:18:22 +01:00
'http://localhost:9000',
2026-03-18 23:39:12 +01:00
...(csp.apiOrigin ? [csp.apiOrigin] : []),
...csp.connectSrc
2025-12-03 09:33:53 +01:00
],
'worker-src': ['self', 'blob:'],
2025-12-03 09:33:53 +01:00
'object-src': ['none'],
'base-uri': ['self'],
'form-action': ['self'],
2026-04-27 11:40:38 +01:00
'frame-ancestors': ['self'],
2025-12-03 09:33:53 +01:00
'report-uri': ['/csp-report']
}
2024-02-29 06:32:40 +00:00
}
2023-08-03 19:24:03 +01:00
}
};
export default config;