Spaces:
Running
Running
fix: make updateLocalEnv compatible with local development
Browse files- 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 |
-
|
12 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|