mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 05:40:02 -06:00
Co-authored-by: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com> Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
32 lines
814 B
TypeScript
32 lines
814 B
TypeScript
import { env } from "@/lib/env";
|
|
import { NextRequest } from "next/server";
|
|
|
|
/**
|
|
* Get the public domain from PUBLIC_URL environment variable
|
|
*/
|
|
export const getPublicDomainHost = (): string | null => {
|
|
const PUBLIC_URL = env.PUBLIC_URL;
|
|
if (!PUBLIC_URL) return null;
|
|
|
|
return new URL(PUBLIC_URL).host;
|
|
};
|
|
|
|
/**
|
|
* Check if PUBLIC_URL is configured (has a valid public domain)
|
|
*/
|
|
export const isPublicDomainConfigured = (): boolean => {
|
|
return getPublicDomainHost() !== null;
|
|
};
|
|
|
|
/**
|
|
* Check if the current request is coming from the public domain
|
|
*/
|
|
export const isRequestFromPublicDomain = (request: NextRequest): boolean => {
|
|
const host = request.headers.get("host");
|
|
const publicDomainHost = getPublicDomainHost();
|
|
|
|
if (!publicDomainHost) return false;
|
|
|
|
return host === publicDomainHost;
|
|
};
|