mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-04 12:50:58 -06:00
32 lines
814 B
TypeScript
32 lines
814 B
TypeScript
import { NextRequest } from "next/server";
|
|
import { env } from "@/lib/env";
|
|
|
|
/**
|
|
* 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;
|
|
};
|