fix: preserve service ID on subdomain change, accept localhost as IP

- serviceUrl() now checks service.url before falling back to buildServiceUrl(id)
- Service update no longer overwrites ID with the new subdomain
- Accept "localhost" as valid IP in service update validation
- Find services by ID or URL match when updating

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 17:38:41 -07:00
parent e5cd8678b0
commit c49d86b0b8
3 changed files with 85 additions and 71 deletions

View File

@@ -422,7 +422,7 @@ module.exports = function(ctx) {
return ctx.errorResponse(res, 400, 'Invalid port number (must be 1-65535)');
}
if (ip && !validatorLib.isIP(ip)) {
if (ip && ip !== 'localhost' && !validatorLib.isIP(ip)) {
return ctx.errorResponse(res, 400, '[DC-210] Invalid IP address');
}
@@ -473,7 +473,7 @@ module.exports = function(ctx) {
if (await exists(ctx.SERVICES_FILE)) {
await ctx.servicesStateManager.update(services => {
const serviceIndex = services.findIndex(s => s.id === oldSubdomain);
const serviceIndex = services.findIndex(s => s.id === oldSubdomain || s.url?.includes(oldSubdomain));
if (serviceIndex !== -1) {
const existing = services[serviceIndex];
const finalPort = port || existing.port;
@@ -481,7 +481,7 @@ module.exports = function(ctx) {
services[serviceIndex] = {
...existing,
id: newSubdomain,
// Keep the original ID — don't change it to the subdomain
port: finalPort,
ip: finalIp,
tailscaleOnly: tailscaleOnly || false,