Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

updateLocalEnv.ts 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  1. import fs from "fs";
  2. import yaml from "js-yaml";
  3. const file = fs.readFileSync("chart/env/prod.yaml", "utf8");
  4. // have to do a weird stringify/parse because of some node error
  5. const prod = JSON.parse(JSON.stringify(yaml.load(file)));
  6. const vars = prod.envVars as Record<string, string>;
  7. let PUBLIC_CONFIG = "";
  8. Object.entries(vars)
  9. // filter keys used in prod with the proxy
  10. .filter(
  11. ([key]) =>
  12. ![
  13. "XFF_DEPTH",
  14. "ADDRESS_HEADER",
  15. "APP_BASE",
  16. "PUBLIC_ORIGIN",
  17. "PUBLIC_SHARE_PREFIX",
  18. "ADMIN_CLI_LOGIN",
  19. ].includes(key)
  20. )
  21. .forEach(([key, value]) => {
  22. PUBLIC_CONFIG += `${key}=\`${value}\`\n`;
  23. });
  24. const SECRET_CONFIG =
  25. (fs.existsSync(".env.SECRET_CONFIG")
  26. ? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
  27. : process.env.SECRET_CONFIG) ?? "";
  28. // Prepend the content of the env variable SECRET_CONFIG
  29. let full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
  30. // replace the internal proxy url with the public endpoint
  31. full_config = full_config.replaceAll(
  32. "https://internal.api-inference.huggingface.co",
  33. "https://router.huggingface.co/hf-inference"
  34. );
  35. full_config = full_config.replaceAll("COOKIE_SECURE=`true`", "COOKIE_SECURE=`false`");
  36. full_config = full_config.replaceAll("LOG_LEVEL=`debug`", "LOG_LEVEL=`info`");
  37. full_config = full_config.replaceAll("NODE_ENV=`prod`", "NODE_ENV=`development`");
  38. // Write full_config to .env.local
  39. fs.writeFileSync(".env.local", full_config);
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...