diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index f042188..347e622 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -6,6 +6,7 @@ import { EVENT_COLUMNS, FILTER_COLUMNS, SESSION_COLUMNS, + hostnameRegex, } from '../../utils/const'; import { parseDateRange } from '../../utils/common'; import { getSessionMetrics, getPageviewMetrics } from '../../model/website'; @@ -160,7 +161,10 @@ export const websiteRouter = router({ z.object({ websiteId: z.string().cuid2(), name: z.string().max(100), - domain: z.union([z.string().max(500).url(), z.string().max(500).ip()]), + domain: z.union([ + z.string().max(500).regex(hostnameRegex), + z.string().max(500).ip(), + ]), monitorId: z.string().cuid2().nullish(), }) ) diff --git a/src/server/utils/const.ts b/src/server/utils/const.ts index f05fb01..0ca870d 100644 --- a/src/server/utils/const.ts +++ b/src/server/utils/const.ts @@ -117,3 +117,6 @@ export const DEFAULT_RESET_DATE = '2000-01-01'; export enum OPENAPI_TAG { USER = 'User', } + +export const hostnameRegex = + /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/gim;