Skip to content

Commit

Permalink
fix: URL compatibility (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyu2001 authored Aug 20, 2024
1 parent b51f011 commit f6049d3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/validators/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengovsg/starter-kitty-validators",
"version": "1.1.1",
"version": "1.1.2",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
Expand Down
5 changes: 3 additions & 2 deletions packages/validators/src/url/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ export const optionsSchema = z.object({
baseOrigin: z
.string()
.transform((value, ctx) => {
if (!URL.canParse(value)) {
try {
return new URL(value)
} catch (error) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Invalid base URL',
})
return z.NEVER
}
return new URL(value)
})
.refine((url) => url.protocol === 'http:' || url.protocol === 'https:', {
message: 'Base URL must use HTTP or HTTPS',
Expand Down

0 comments on commit f6049d3

Please sign in to comment.