mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 01:36:39 +00:00
Merge pull request #1394 from Pallavikumarimdb/Fix/hostname-field-reset-port-and-method
Fix/hostname field reset port and method
This commit is contained in:
@@ -649,24 +649,33 @@ export default function ReverseProxyTargets(props: {
|
|||||||
defaultValue={row.original.ip}
|
defaultValue={row.original.ip}
|
||||||
className="min-w-[150px]"
|
className="min-w-[150px]"
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const parsed = parseHostTarget(e.target.value);
|
const input = e.target.value.trim();
|
||||||
if (parsed) {
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
updateTarget(row.original.targetId, {
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
...row.original,
|
|
||||||
method: parsed.protocol,
|
if (hasProtocol || hasPort) {
|
||||||
ip: parsed.host,
|
const parsed = parseHostTarget(input);
|
||||||
port: parsed.port
|
if (parsed) {
|
||||||
});
|
updateTarget(row.original.targetId, {
|
||||||
|
...row.original,
|
||||||
|
method: hasProtocol ? parsed.protocol : row.original.method,
|
||||||
|
ip: parsed.host,
|
||||||
|
port: hasPort ? parsed.port : row.original.port
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
updateTarget(row.original.targetId, {
|
||||||
|
...row.original,
|
||||||
|
ip: input
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
updateTarget(row.original.targetId, {
|
updateTarget(row.original.targetId, {
|
||||||
...row.original,
|
...row.original,
|
||||||
ip: e.target.value
|
ip: input
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -961,11 +970,21 @@ export default function ReverseProxyTargets(props: {
|
|||||||
id="ip"
|
id="ip"
|
||||||
{...field}
|
{...field}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const parsed = parseHostTarget(e.target.value);
|
const input = e.target.value.trim();
|
||||||
if (parsed) {
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
addTargetForm.setValue("method", parsed.protocol);
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
addTargetForm.setValue("ip", parsed.host);
|
|
||||||
addTargetForm.setValue("port", parsed.port);
|
if (hasProtocol || hasPort) {
|
||||||
|
const parsed = parseHostTarget(input);
|
||||||
|
if (parsed) {
|
||||||
|
if (hasProtocol || !addTargetForm.getValues("method")) {
|
||||||
|
addTargetForm.setValue("method", parsed.protocol);
|
||||||
|
}
|
||||||
|
addTargetForm.setValue("ip", parsed.host);
|
||||||
|
if (hasPort || !addTargetForm.getValues("port")) {
|
||||||
|
addTargetForm.setValue("port", parsed.port);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
field.onBlur();
|
field.onBlur();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
|
|
||||||
export function parseHostTarget(input: string) {
|
export function parseHostTarget(input: string) {
|
||||||
try {
|
try {
|
||||||
const normalized = input.match(/^https?:\/\//) ? input : `http://${input}`;
|
const normalized = input.match(/^(https?|h2c):\/\//) ? input : `http://${input}`;
|
||||||
const url = new URL(normalized);
|
const url = new URL(normalized);
|
||||||
|
|
||||||
const protocol = url.protocol.replace(":", ""); // http | https
|
const protocol = url.protocol.replace(":", ""); // http | https | h2c
|
||||||
const host = url.hostname;
|
const host = url.hostname;
|
||||||
const port = url.port ? parseInt(url.port, 10) : protocol === "https" ? 443 : 80;
|
|
||||||
|
let defaultPort: number;
|
||||||
|
switch (protocol) {
|
||||||
|
case "https":
|
||||||
|
defaultPort = 443;
|
||||||
|
break;
|
||||||
|
case "h2c":
|
||||||
|
defaultPort = 80;
|
||||||
|
break;
|
||||||
|
default: // http
|
||||||
|
defaultPort = 80;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const port = url.port ? parseInt(url.port, 10) : defaultPort;
|
||||||
|
|
||||||
return { protocol, host, port };
|
return { protocol, host, port };
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user