client.ts 607 B

123456789101112131415161718192021222324252627
  1. import { BuildConfig, getBuildConfig } from "./build";
  2. export function getClientConfig() {
  3. if (typeof document !== "undefined") {
  4. // client side
  5. return JSON.parse(queryMeta("config")) as BuildConfig;
  6. }
  7. if (typeof process !== "undefined") {
  8. // server side
  9. return getBuildConfig();
  10. }
  11. }
  12. function queryMeta(key: string, defaultValue?: string): string {
  13. let ret: string;
  14. if (document) {
  15. const meta = document.head.querySelector(
  16. `meta[name='${key}']`,
  17. ) as HTMLMetaElement;
  18. ret = meta?.content ?? "";
  19. } else {
  20. ret = defaultValue ?? "";
  21. }
  22. return ret;
  23. }