nsarrazin HF Staff commited on
Commit
648b4e8
·
1 Parent(s): 73de8f0

fix: make updateLocalEnv compatible with local development

Browse files
Files changed (1) hide show
  1. scripts/updateLocalEnv.ts +16 -4
scripts/updateLocalEnv.ts CHANGED
@@ -8,9 +8,13 @@ const prod = JSON.parse(JSON.stringify(yaml.load(file)));
8
  const vars = prod.envVars as Record<string, string>;
9
 
10
  let PUBLIC_CONFIG = "";
11
- Object.entries(vars).forEach(([key, value]) => {
12
- PUBLIC_CONFIG += `${key}=\`${value}\`\n`;
13
- });
 
 
 
 
14
 
15
  const SECRET_CONFIG =
16
  (fs.existsSync(".env.SECRET_CONFIG")
@@ -18,7 +22,15 @@ const SECRET_CONFIG =
18
  : process.env.SECRET_CONFIG) ?? "";
19
 
20
  // Prepend the content of the env variable SECRET_CONFIG
21
- const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
 
 
 
 
 
 
 
 
22
 
23
  // Write full_config to .env.local
24
  fs.writeFileSync(".env.local", full_config);
 
8
  const vars = prod.envVars as Record<string, string>;
9
 
10
  let PUBLIC_CONFIG = "";
11
+
12
+ Object.entries(vars)
13
+ // filter keys used in prod with the proxy
14
+ .filter(([key]) => !["XFF_DEPTH", "ADDRESS_HEADER"].includes(key))
15
+ .forEach(([key, value]) => {
16
+ PUBLIC_CONFIG += `${key}=\`${value}\`\n`;
17
+ });
18
 
19
  const SECRET_CONFIG =
20
  (fs.existsSync(".env.SECRET_CONFIG")
 
22
  : process.env.SECRET_CONFIG) ?? "";
23
 
24
  // Prepend the content of the env variable SECRET_CONFIG
25
+ let full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
26
+
27
+ // replace the internal proxy url with the public endpoint
28
+ full_config = full_config.replaceAll(
29
+ "https://proxy.serverless.api-inference.huggingface.tech",
30
+ "https://api-inference.huggingface.co"
31
+ );
32
+
33
+ console.log(full_config);
34
 
35
  // Write full_config to .env.local
36
  fs.writeFileSync(".env.local", full_config);