mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-26 03:35:38 -05:00
8f8b549b1d
Co-authored-by: Victor Santos <victor@formbricks.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
/**
|
|
* Routes that should be accessible on the public domain (PUBLIC_URL)
|
|
* Uses whitelist approach - only these routes are allowed on public domain
|
|
*/
|
|
const PUBLIC_ROUTES = {
|
|
// Survey routes
|
|
SURVEY_ROUTES: [
|
|
/^\/s\/[^/]+/, // /s/[surveyId] - survey pages
|
|
/^\/c\/[^/]+/, // /c/[jwt] - contact survey pages
|
|
],
|
|
|
|
// API routes accessible from public domain
|
|
API_ROUTES: [
|
|
/^\/api\/v[12]\/client\//, // /api/v1/client/** and /api/v2/client/**
|
|
],
|
|
} as const;
|
|
|
|
const COMMON_ROUTES = {
|
|
HEALTH_ROUTES: [/^\/health$/], // /health endpoint
|
|
PUBLIC_STORAGE_ROUTES: [
|
|
/^\/storage\/[^/]+\/public\//, // /storage/[environmentId]/public/** - public storage
|
|
],
|
|
} as const;
|
|
|
|
/**
|
|
* Get public only route patterns as a flat array
|
|
*/
|
|
export const getPublicDomainRoutePatterns = (): RegExp[] => {
|
|
return Object.values(PUBLIC_ROUTES).flat();
|
|
};
|
|
|
|
/**
|
|
* Get all public route patterns as a flat array
|
|
*/
|
|
export const getAllPubliclyAccessibleRoutePatterns = (): RegExp[] => {
|
|
const routes = {
|
|
...PUBLIC_ROUTES,
|
|
...COMMON_ROUTES,
|
|
};
|
|
|
|
return Object.values(routes).flat();
|
|
};
|
|
|
|
/**
|
|
* Check if a URL matches any of the given route patterns
|
|
*/
|
|
export const matchesAnyPattern = (url: string, patterns: RegExp[]): boolean => {
|
|
return patterns.some((pattern) => pattern.test(url));
|
|
};
|