-
Notifications
You must be signed in to change notification settings - Fork 1
/
svelte.config.js
70 lines (64 loc) · 2.01 KB
/
svelte.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as child_process from 'node:child_process';
import adapterCloudflare from '@sveltejs/adapter-cloudflare';
import adapterNode from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import dotenv from 'dotenv';
import process from 'process';
// Determine if we are running on Cloudflare Pages
const isCloudflare = process.env.CF_PAGES === '1';
// Use the appropriate adapter
const adapter = isCloudflare ? adapterCloudflare : adapterNode;
function readEnv(path) {
return dotenv.config({ path })?.parsed ?? {};
}
const env = {
...process.env,
...readEnv('.env'),
...readEnv(`.env.${process.env.NODE_ENV}`),
...readEnv('.env.local'),
};
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte'],
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess()],
vitePlugin: {
inspector: true,
},
kit: {
adapter: adapter({
routes: {
include: ['/*'],
exclude: ['<all>'],
},
}),
csp: {
mode: 'hash',
directives: {
'default-src': ['self'],
'child-src': ['https://challenges.cloudflare.com'],
'frame-src': ['https://challenges.cloudflare.com'], // Deprecated
'img-src': ['self', 'https://www.gravatar.com'],
'connect-src': [
'self',
'https://' + env.PUBLIC_BACKEND_API_DOMAIN,
'wss://' + env.PUBLIC_BACKEND_API_DOMAIN,
'wss://' + env.PUBLIC_GATEWAY_CSP_WILDCARD,
'https://firmware.openshock.org',
'https://api.pwnedpasswords.com/range/',
'https://cloudflareinsights.com',
],
'script-src': [
'self',
'https://challenges.cloudflare.com/turnstile/',
'https://static.cloudflareinsights.com',
],
},
},
version: {
name: process.env.GIT_HASH ?? child_process.execSync('git rev-parse HEAD').toString().trim(),
},
},
};
export default config;