fix(remote-proxy): fix TypeError and make port optional with protocol defaults

- Fix TypeError: error.code?.toLowerCase - add type guard for non-string error codes
- Make remote proxy port optional - defaults to 443 (HTTPS) or 80 (HTTP)
- Smart URL building - omits port when using protocol default
- UI improvements - show default port hint, allow empty port field
- Better validation - only host is required, port uses smart defaults

Closes #142
This commit is contained in:
kaitranntt
2025-12-19 04:23:20 -05:00
parent 40fea0ef04
commit 03aea4eac2
7 changed files with 111 additions and 29 deletions
+9 -3
View File
@@ -72,14 +72,20 @@ router.post('/test', async (req: Request, res: Response) => {
try {
const { host, port, protocol, authToken, allowSelfSigned } = req.body;
if (!host || !port) {
res.status(400).json({ error: 'Host and port are required' });
// Host is required, port is optional (uses protocol defaults)
if (!host) {
res.status(400).json({ error: 'Host is required' });
return;
}
// Parse port - treat empty string, 0, null as "use default"
const parsedPort = port && port !== '' ? parseInt(String(port), 10) : undefined;
const effectivePort =
parsedPort && !isNaN(parsedPort) && parsedPort > 0 ? parsedPort : undefined;
const status = await testConnection({
host,
port: typeof port === 'number' ? port : parseInt(port, 10),
port: effectivePort,
protocol: protocol || 'http',
authToken,
allowSelfSigned: allowSelfSigned || false,