-
Notifications
You must be signed in to change notification settings - Fork 2
Feature | Redirection #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41b9c2a
feat: add redirect URL functionality for domain management
mukezhz fb48710
feat: include redirect URL in domain check results
mukezhz e2fc548
fix: standardize error handling in domain addition route
mukezhz 5503653
Update src/app/api/domain/add/route.ts
mukezhz f71a28b
Update src/components/proxies/add-proxy-dialog.tsx
mukezhz 7f2a96a
fix: update port handling in domain addition and proxy dialog
mukezhz e3ea9e6
fix: trim whitespace for redirect domain validation
mukezhz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20250409071302_add_redirect_url/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Domains" ADD COLUMN "redirectUrl" TEXT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,27 +1,61 @@ | ||||||
import { z } from "zod"; | ||||||
|
||||||
const domainRegex = /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; | ||||||
// Updated regex to accept localhost and other local development domains | ||||||
const domainRegex = /^[a-zA-Z0-9.-]+\.[a-zA-Z0-9]{1,}$/; | ||||||
|
||||||
const domainOrIpOrDockerRegex = | ||||||
/^(?:[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}|\b\d{1,3}(\.\d{1,3}){3}\b|\[?[a-fA-F0-9:]+\]?|[a-zA-Z0-9_-]+)$/; | ||||||
/^(?:[a-zA-Z0-9.-]+\.[a-zA-Z0-9]{1,}|\b\d{1,3}(\.\d{1,3}){3}\b|\[?[a-fA-F0-9:]+\]?|[a-zA-Z0-9_-]+)$/; | ||||||
|
||||||
export const addDomainSchema = z.object({ | ||||||
incomingAddress: z | ||||||
domain: z | ||||||
.string() | ||||||
.min(1, "Incoming address is required") | ||||||
.min(1, "Domain is required") | ||||||
.refine((value) => domainRegex.test(value), { | ||||||
message: | ||||||
"Invalid domain format (must be a plain domain, e.g., example.com)", | ||||||
}), | ||||||
enableRedirection: z.boolean().default(false), | ||||||
redirectTo: z.string().optional(), | ||||||
destinationAddress: z | ||||||
.string() | ||||||
.min(1, "Destination address is required") | ||||||
.refine((value) => domainOrIpOrDockerRegex.test(value), { | ||||||
message: | ||||||
"Invalid address format (must be a domain, IP, service name etc.)", | ||||||
}), | ||||||
port: z.string().min(1, "Port is required"), | ||||||
.string(), | ||||||
port: z.string(), | ||||||
enableHttps: z.boolean().default(true), | ||||||
}).superRefine((data, ctx) => { | ||||||
const issues = []; | ||||||
|
||||||
if (data.enableRedirection && data.redirectTo) { | ||||||
if (!domainRegex.test(data.redirectTo.trim())) { | ||||||
ctx.addIssue({ | ||||||
path: ["redirectTo"], | ||||||
message: "Invalid redirect domain format", | ||||||
code: z.ZodIssueCode.custom, | ||||||
}); | ||||||
issues.push("redirectTo"); | ||||||
} | ||||||
} | ||||||
|
||||||
if (!data.enableRedirection) { | ||||||
const portNumber = parseInt(data.port, 10); | ||||||
if (isNaN(portNumber) || portNumber < 1 || portNumber > 65535) { | ||||||
ctx.addIssue({ | ||||||
path: ["port"], | ||||||
message: "Invalid port number", | ||||||
code: z.ZodIssueCode.custom, | ||||||
}); | ||||||
issues.push("port"); | ||||||
} | ||||||
|
||||||
if (!domainOrIpOrDockerRegex.test(data.destinationAddress)) { | ||||||
ctx.addIssue({ | ||||||
path: ["destinationAddress"], | ||||||
message: "Invalid destination address format", | ||||||
code: z.ZodIssueCode.custom, | ||||||
}); | ||||||
issues.push("destinationAddress"); | ||||||
} | ||||||
} | ||||||
|
||||||
return issues.length === 0; | ||||||
Comment on lines
+57
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The superRefine callback in Zod is intended for adding custom issues and should not return a value. Remove the return statement to adhere to the expected callback signature.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
}); | ||||||
|
||||||
export type AddDomainValues = z.infer<typeof addDomainSchema> | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When redirection is enabled, the schema currently only refines the redirectTo field if a value is provided; consider enforcing a non-empty redirectTo when enableRedirection is true to avoid misconfiguration.
Copilot uses AI. Check for mistakes.