@c15t/nextjs
Version:
Developer-first CMP for Next.js: cookie banner, consent manager, preferences centre. GDPR ready with minimal setup and rich customization.
1 lines • 879 B
JavaScript
let e=/^https?:\/\//;function t(e){return"/"===e?e:e.endsWith("/")?e.slice(0,-1):e}function r(r){if(e.test(r))return new URL(r),{isAbsolute:!0,normalizedURL:t(r)};if(r.startsWith("/"))return{isAbsolute:!1,normalizedURL:t(r)};throw Error(`Invalid URL format: ${r}. URL must be absolute (https://...) or relative starting with (/)`)}function n(e,n){try{let{normalizedURL:o,isAbsolute:l}=r(e);if(l)return o;let i=n.get("referer"),s=n.get("x-forwarded-proto")||"https",a=n.get("x-forwarded-host")||n.get("host");if(a)return t(`${s}://${a}${o}`);if(i){let e=new URL(i);return t(`${e.protocol}//${e.host}${o}`)}return"development"===process.env.NODE_ENV&&console.warn("Could not determine base URL for relative backend URL"),null}catch(e){return"development"===process.env.NODE_ENV&&console.warn("Invalid backend URL:",e),null}}export{n as normalizeBackendURL,r as validateBackendURL};