@@ -31,6 +31,28 @@ function getGitBranch() {
3131 return child_process . execSync ( 'git rev-parse --abbrev-ref HEAD' ) . toString ( ) . trim ( ) ;
3232}
3333
34+ function getWsUrlFromHttpUrl ( url ) {
35+ if ( url . startsWith ( 'https://' ) ) {
36+ return url . replace ( 'https://' , 'wss://' ) ;
37+ } else if ( url . startsWith ( 'http://' ) ) {
38+ return url . replace ( 'http://' , 'ws://' ) ;
39+ }
40+
41+ throw new Error ( `Invalid URL was provided, it must start with http:// or https:// [${ url } ]` ) ;
42+ }
43+
44+ function getSvelteBasePath ( ) {
45+ try {
46+ const url = new URL ( dotenv . PUBLIC_SITE_URL ) ;
47+ const path = url . pathname === '/' ? '' : url . pathname ;
48+ console . log ( `Using base path: [${ path } ] from PUBLIC_SITE_URL: ${ dotenv . PUBLIC_SITE_URL } ` ) ;
49+ return path ;
50+ } catch ( error ) {
51+ throw new Error ( `PUBLIC_SITE_URL is not a valid URL: ${ error . message } ` , { cause : error } ) ;
52+ }
53+
54+ }
55+
3456const commitHash = getGitHash ( ) ;
3557const branchName = getGitBranch ( ) ;
3658
@@ -49,6 +71,9 @@ const config = {
4971 } ,
5072 kit : {
5173 adapter : adapter ( ) ,
74+ paths : {
75+ base : getSvelteBasePath ( )
76+ } ,
5277 csp : {
5378 mode : 'hash' ,
5479 directives : {
@@ -65,9 +90,10 @@ const config = {
6590 ] ,
6691 'connect-src' : [
6792 'self' ,
68- 'https://' + dotenv . PUBLIC_BACKEND_API_DOMAIN ,
69- 'wss://' + dotenv . PUBLIC_BACKEND_API_DOMAIN ,
70- 'wss://' + dotenv . PUBLIC_GATEWAY_CSP_WILDCARD ,
93+ dotenv . PUBLIC_BACKEND_API_URL ,
94+ getWsUrlFromHttpUrl ( dotenv . PUBLIC_BACKEND_API_URL ) ,
95+ dotenv . PUBLIC_GATEWAY_CSP_WILDCARD ,
96+ getWsUrlFromHttpUrl ( dotenv . PUBLIC_GATEWAY_CSP_WILDCARD ) ,
7197 'https://firmware.openshock.org' ,
7298 'https://api.pwnedpasswords.com/range/' ,
7399 'https://cloudflareinsights.com' ,
0 commit comments