fix local and preview config

This commit is contained in:
Sara
2023-11-02 12:11:01 +01:00
committed by Mathieu Virbel
parent 5a92080e8c
commit 61d1e6b06b
2 changed files with 19 additions and 2 deletions

View File

@@ -1,4 +1,15 @@
import { get } from "@vercel/edge-config";
import { isDevelopment } from "./utils";
const localConfig = {
features: {
requireLogin: true,
privacy: true,
browse: true,
},
api_url: "http://127.0.0.1:1250",
auth_callback_url: "http://localhost:3000/auth-callback",
};
type EdgeConfig = {
[domainWithDash: string]: {
@@ -23,7 +34,14 @@ export function edgeDomainToKey(domain: string) {
// get edge config server-side (prefer DomainContext when available), domain is the hostname
export async function getConfig(domain: string) {
const config = await get(edgeDomainToKey(domain));
if (isDevelopment()) {
return localConfig;
}
let config = await get(edgeDomainToKey(domain));
console.warn("No config for this domain, falling back to default");
config = await get(edgeDomainToKey("default"));
if (typeof config !== "object") throw Error("Error fetchig config");