@dmno/nextjs-integration
Version:
tools for integrating dmno into nextjs
29 lines (28 loc) • 1.16 kB
JavaScript
// src/inject-dmno-client.ts
console.log("injected DMNO into client code");
window.DMNO_CONFIG = new Proxy({}, {
get(o, key) {
throw new Error(`\u{1F4A5} \`DMNO_CONFIG\` is not accessible on the client, use \`DMNO_PUBLIC_CONFIG.${key.toString()}\` instead`);
}
});
window.DMNO_PUBLIC_CONFIG = new Proxy({}, {
get(o, key) {
if (!window._DMNO_DYNAMIC_PUBLIC_CONFIG) {
const request = new XMLHttpRequest();
request.open("GET", "/api/fetch-dynamic-public-config", false);
request.send(null);
if (request.status !== 200) {
throw new Error("Failed to load public dynamic config");
}
window._DMNO_PUBLIC_DYNAMIC_CONFIG = JSON.parse(request.responseText);
console.log("loaded public dynamic config", window._DMNO_PUBLIC_DYNAMIC_CONFIG);
}
if (key in window._DMNO_PUBLIC_DYNAMIC_CONFIG) {
return window._DMNO_PUBLIC_DYNAMIC_CONFIG[key];
}
throw new Error(`\u{1F4A5} \`DMNO_PUBLIC_CONFIG.${key.toString()}\` does not exist in your config, or it is sensitive `);
}
});
//# sourceMappingURL=inject-dmno-client.cjs.map
//# sourceMappingURL=inject-dmno-client.cjs.map
;