mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 04:19:49 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user