@@ -3,6 +3,8 @@ import { useState } from 'react'
33import { ENV } from 'varlock/env'
44import { env } from 'cloudflare:workers'
55
6+ declare const __USE_CF__ : boolean
7+
68function redact ( val : string | undefined ) {
79 if ( val === undefined || val === null ) return { set : false , length : 0 }
810 return { set : true , length : val . length }
@@ -20,27 +22,32 @@ export const Route = createFileRoute('/api-route')({
2022 vars : {
2123 SENSITIVE_VAR : {
2224 varlock : redact ( ENV . SENSITIVE_VAR ) ,
23- cloudflare : redact ( env . SENSITIVE_VAR ) ,
25+ processEnv : redact ( process . env . SENSITIVE_VAR ) ,
26+ ...( __USE_CF__ && { cloudflare : redact ( env . SENSITIVE_VAR ) } ) ,
2427 importMeta : redact ( import . meta. env . SENSITIVE_VAR ) ,
2528 } ,
2629 ANOTHER_SECRET : {
2730 varlock : redact ( ENV . ANOTHER_SECRET ) ,
28- cloudflare : redact ( env . ANOTHER_SECRET ) ,
31+ processEnv : redact ( process . env . ANOTHER_SECRET ) ,
32+ ...( __USE_CF__ && { cloudflare : redact ( env . ANOTHER_SECRET ) } ) ,
2933 importMeta : redact ( import . meta. env . ANOTHER_SECRET ) ,
3034 } ,
3135 PUBLIC_ITEM : {
3236 varlock : redact ( ENV . PUBLIC_ITEM ) ,
33- cloudflare : redact ( env . PUBLIC_ITEM ) ,
37+ processEnv : redact ( process . env . PUBLIC_ITEM ) ,
38+ ...( __USE_CF__ && { cloudflare : redact ( env . PUBLIC_ITEM ) } ) ,
3439 importMeta : redact ( import . meta. env . PUBLIC_ITEM ) ,
3540 } ,
3641 PUBLIC_OTHER : {
3742 varlock : redact ( ENV . PUBLIC_OTHER ) ,
38- cloudflare : redact ( env . PUBLIC_OTHER ) ,
43+ processEnv : redact ( process . env . PUBLIC_OTHER ) ,
44+ ...( __USE_CF__ && { cloudflare : redact ( env . PUBLIC_OTHER ) } ) ,
3945 importMeta : redact ( import . meta. env . PUBLIC_OTHER ) ,
4046 } ,
4147 VITE_PREFIXED_ITEM : {
4248 varlock : redact ( ENV . VITE_PREFIXED_ITEM ) ,
43- cloudflare : redact ( env . VITE_PREFIXED_ITEM ) ,
49+ processEnv : redact ( process . env . VITE_PREFIXED_ITEM ) ,
50+ ...( __USE_CF__ && { cloudflare : redact ( env . VITE_PREFIXED_ITEM ) } ) ,
4451 importMeta : redact ( import . meta. env . VITE_PREFIXED_ITEM ) ,
4552 } ,
4653 } ,
@@ -52,13 +59,13 @@ export const Route = createFileRoute('/api-route')({
5259} )
5360
5461type RedactedInfo = { set : boolean ; length : number }
55- type EnvResult = {
56- leaked : string | undefined
57- vars : Record < string , { varlock : RedactedInfo ; cloudflare : RedactedInfo ; importMeta : RedactedInfo } >
58- }
62+ type VarRow = { varlock : RedactedInfo ; processEnv : RedactedInfo ; cloudflare ?: RedactedInfo ; importMeta : RedactedInfo }
5963
6064function ApiRoutePage ( ) {
61- const [ data , setData ] = useState < EnvResult | null > ( null )
65+ const [ data , setData ] = useState < {
66+ leaked : string | undefined
67+ vars : Record < string , VarRow >
68+ } | null > ( null )
6269 const [ loading , setLoading ] = useState ( false )
6370
6471 const handleFetch = async ( leak : boolean ) => {
@@ -71,6 +78,9 @@ function ApiRoutePage() {
7178 }
7279 }
7380
81+ const varNames = [ 'SENSITIVE_VAR' , 'ANOTHER_SECRET' , 'PUBLIC_ITEM' , 'PUBLIC_OTHER' , 'VITE_PREFIXED_ITEM' ] as const
82+ const showCf = data ? 'cloudflare' in data . vars [ varNames [ 0 ] ] : false
83+
7484 return (
7585 < main className = "page-wrap px-4 pb-8 pt-14" >
7686 < h1 className = "display-title mb-6 text-3xl font-bold text-[var(--sea-ink)]" >
@@ -112,13 +122,14 @@ function ApiRoutePage() {
112122 < thead >
113123 < tr className = "border-b border-[var(--line)]" >
114124 < th className = "py-2 pr-4" > Variable</ th >
115- < th className = "py-2 pr-4 font-mono text-xs" > ENV.xx</ th >
116- < th className = "py-2 pr-4 font-mono text-xs" > env.xx</ th >
117- < th className = "py-2 font-mono text-xs" > import.meta.env.xx</ th >
125+ < th className = "py-2 pr-4 font-mono text-xs" > < code > ENV</ code > (varlock)</ th >
126+ < th className = "py-2 pr-4 font-mono text-xs" > < code > process.env</ code > </ th >
127+ { showCf && < th className = "py-2 pr-4 font-mono text-xs" > < code > env</ code > (cloudflare)</ th > }
128+ < th className = "py-2 font-mono text-xs" > < code > import.meta.env</ code > </ th >
118129 </ tr >
119130 </ thead >
120131 < tbody >
121- { ( [ 'SENSITIVE_VAR' , 'ANOTHER_SECRET' , 'PUBLIC_ITEM' , 'PUBLIC_OTHER' , 'VITE_PREFIXED_ITEM' ] as const ) . map ( ( name ) => {
132+ { varNames . map ( ( name ) => {
122133 const row = data . vars [ name ]
123134 if ( ! row ) return null
124135 return (
@@ -127,7 +138,8 @@ function ApiRoutePage() {
127138 { name }
128139 </ td >
129140 < td className = "py-2 pr-4" > < RedactedCell info = { row . varlock } /> </ td >
130- < td className = "py-2 pr-4" > < RedactedCell info = { row . cloudflare } /> </ td >
141+ < td className = "py-2 pr-4" > < RedactedCell info = { row . processEnv } /> </ td >
142+ { showCf && < td className = "py-2 pr-4" > < RedactedCell info = { row . cloudflare } /> </ td > }
131143 < td className = "py-2" > < RedactedCell info = { row . importMeta } /> </ td >
132144 </ tr >
133145 )
@@ -140,7 +152,8 @@ function ApiRoutePage() {
140152 )
141153}
142154
143- function RedactedCell ( { info } : { info : RedactedInfo } ) {
155+ function RedactedCell ( { info } : { info : RedactedInfo | undefined } ) {
156+ if ( ! info ) return < span className = "font-mono text-xs text-gray-400" > —</ span >
144157 return (
145158 < span className = "font-mono text-xs" >
146159 { info . set ? (
0 commit comments