diff --git a/cloud.go b/cloud.go index fc41a36..5cf00c2 100644 --- a/cloud.go +++ b/cloud.go @@ -96,7 +96,6 @@ func handleCloudRegister(c *gin.Context) { } config.CloudToken = tokenResp.SecretToken - config.CloudURL = req.CloudAPI provider, err := oidc.NewProvider(c, "https://accounts.google.com") if err != nil { @@ -298,8 +297,8 @@ func rpcDeregisterDevice() error { // (e.g., wrong cloud token, already deregistered). Regardless of the reason, we can safely remove it. if resp.StatusCode == http.StatusNotFound || (resp.StatusCode >= 200 && resp.StatusCode < 300) { config.CloudToken = "" - config.CloudURL = "" config.GoogleIdentity = "" + if err := SaveConfig(); err != nil { return fmt.Errorf("failed to save configuration after deregistering: %w", err) } diff --git a/jsonrpc.go b/jsonrpc.go index 619e561..1de55b2 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -730,6 +730,33 @@ func rpcSetSerialSettings(settings SerialSettings) error { return nil } +func rpcSetCloudUrl(url string) error { + if url == "" { + // Reset to default by removing from config + config.CloudURL = defaultConfig.CloudURL + } else { + config.CloudURL = url + } + + if err := SaveConfig(); err != nil { + return fmt.Errorf("failed to save config: %w", err) + } + return nil +} + +func rpcGetCloudUrl() (string, error) { + return config.CloudURL, nil +} + +func rpcResetCloudUrl() error { + // Reset to default by removing from config + config.CloudURL = defaultConfig.CloudURL + if err := SaveConfig(); err != nil { + return fmt.Errorf("failed to reset cloud URL: %w", err) + } + return nil +} + var rpcHandlers = map[string]RPCHandler{ "ping": {Func: rpcPing}, "getDeviceID": {Func: rpcGetDeviceID}, @@ -786,4 +813,7 @@ var rpcHandlers = map[string]RPCHandler{ "setATXPowerAction": {Func: rpcSetATXPowerAction, Params: []string{"action"}}, "getSerialSettings": {Func: rpcGetSerialSettings}, "setSerialSettings": {Func: rpcSetSerialSettings, Params: []string{"settings"}}, + "setCloudUrl": {Func: rpcSetCloudUrl, Params: []string{"url"}}, + "getCloudUrl": {Func: rpcGetCloudUrl}, + "resetCloudUrl": {Func: rpcResetCloudUrl}, } diff --git a/ui/.env.cloud-development b/ui/.env.cloud-development new file mode 100644 index 0000000..471e280 --- /dev/null +++ b/ui/.env.cloud-development @@ -0,0 +1,4 @@ +# No need for VITE_CLOUD_APP it's only needed for the device build + +# We use this for all the cloud API requests from the browser +VITE_CLOUD_API=http://localhost:3000 diff --git a/ui/.env.cloud-production b/ui/.env.cloud-production new file mode 100644 index 0000000..d9895d2 --- /dev/null +++ b/ui/.env.cloud-production @@ -0,0 +1,4 @@ +# No need for VITE_CLOUD_APP it's only needed for the device build + +# We use this for all the cloud API requests from the browser +VITE_CLOUD_API=https://api.jetkvm.com diff --git a/ui/.env.cloud-staging b/ui/.env.cloud-staging new file mode 100644 index 0000000..bc5c14c --- /dev/null +++ b/ui/.env.cloud-staging @@ -0,0 +1,4 @@ +# No need for VITE_CLOUD_APP it's only needed for the device build + +# We use this for all the cloud API requests from the browser +VITE_CLOUD_API=https://staging-api.jetkvm.com diff --git a/ui/.env.development b/ui/.env.development deleted file mode 100644 index 172328c..0000000 --- a/ui/.env.development +++ /dev/null @@ -1,6 +0,0 @@ -VITE_SIGNAL_API=http://localhost:3000 - -VITE_CLOUD_APP=http://localhost:5173 -VITE_CLOUD_API=http://localhost:3000 - -VITE_JETKVM_HEAD= \ No newline at end of file diff --git a/ui/.env.device b/ui/.env.device index 2aaa6a7..252fac4 100644 --- a/ui/.env.device +++ b/ui/.env.device @@ -1,6 +1,2 @@ -VITE_SIGNAL_API= # Uses the KVM device's IP address as the signal API endpoint - -VITE_CLOUD_APP=https://app.jetkvm.com -VITE_CLOUD_API=https://api.jetkvm.com - -VITE_JETKVM_HEAD= \ No newline at end of file +# Used in settings page to know where to link to when user wants to adopt a device to the cloud +VITE_CLOUD_APP=http://localhost:5173 diff --git a/ui/.env.production b/ui/.env.production deleted file mode 100644 index 2587c0c..0000000 --- a/ui/.env.production +++ /dev/null @@ -1,6 +0,0 @@ -VITE_SIGNAL_API=https://api.jetkvm.com - -VITE_CLOUD_APP=https://app.jetkvm.com -VITE_CLOUD_API=https://api.jetkvm.com - -VITE_JETKVM_HEAD= \ No newline at end of file diff --git a/ui/.env.staging b/ui/.env.staging deleted file mode 100644 index 651e5bc..0000000 --- a/ui/.env.staging +++ /dev/null @@ -1,4 +0,0 @@ -VITE_SIGNAL_API=https://staging-api.jetkvm.com - -VITE_CLOUD_APP=https://staging-app.jetkvm.com -VITE_CLOUD_API=https://staging-api.jetkvm.com \ No newline at end of file diff --git a/ui/index.html b/ui/index.html index 72d2594..af9bdfb 100644 --- a/ui/index.html +++ b/ui/index.html @@ -28,7 +28,6 @@ JetKVM - %VITE_JETKVM_HEAD%