1
1
import { useStore } from '@nanostores/react' ;
2
- import type { LinksFunction } from '@remix-run/cloudflare' ;
3
- import { Links , Meta , Outlet , Scripts , ScrollRestoration } from '@remix-run/react' ;
2
+ import type { LinksFunction , LoaderFunction } from '@remix-run/cloudflare' ;
3
+ import { json } from '@remix-run/cloudflare' ;
4
+ import { Links , Meta , Outlet , Scripts , ScrollRestoration , useLoaderData } from '@remix-run/react' ;
4
5
import tailwindReset from '@unocss/reset/tailwind-compat.css?url' ;
5
6
import { themeStore } from './lib/stores/theme' ;
6
7
import { stripIndents } from './utils/stripIndent' ;
7
8
import { createHead } from 'remix-island' ;
8
9
import { useEffect } from 'react' ;
10
+ import { env } from 'node:process' ;
9
11
10
12
import reactToastifyStyles from 'react-toastify/dist/ReactToastify.css?url' ;
11
13
import globalStyles from './styles/index.scss?url' ;
@@ -62,9 +64,17 @@ export const Head = createHead(() => (
62
64
</ >
63
65
) ) ;
64
66
67
+ export const loader : LoaderFunction = async ( ) => {
68
+ return json ( {
69
+ ENV : {
70
+ OSS_HOST : env . VITE_OSS_BASE_URL ,
71
+ } ,
72
+ } ) ;
73
+ } ;
74
+
65
75
export function Layout ( { children } : { children : React . ReactNode } ) {
66
76
const theme = useStore ( themeStore ) ;
67
-
77
+ const data = useLoaderData < typeof loader > ( ) as { ENV : { OSS_HOST : string } } ;
68
78
useEffect ( ( ) => {
69
79
document . querySelector ( 'html' ) ?. setAttribute ( 'data-theme' , theme ) ;
70
80
} , [ theme ] ) ;
@@ -73,6 +83,11 @@ export function Layout({ children }: { children: React.ReactNode }) {
73
83
< >
74
84
{ children }
75
85
< ScrollRestoration />
86
+ < script
87
+ dangerouslySetInnerHTML = { {
88
+ __html : `window.ENV = ${ JSON . stringify ( data . ENV ) } ` ,
89
+ } }
90
+ />
76
91
< Scripts />
77
92
</ >
78
93
) ;
0 commit comments