Skip to content

Commit 7304e6b

Browse files
feat(cloud): Add custom cloud API URL configuration support (#181)
* feat(cloud): Add custom cloud API URL configuration support - Implement RPC methods to set, get, and reset cloud URL - Update cloud registration to remove hardcoded cloud API URL - Modify UI to allow configuring custom cloud API URL in developer settings - Remove environment-specific cloud configuration files - Simplify cloud URL configuration in UI config * fix(ui): Update cloud app URL to production environment in device mode * refactor(ui): Remove SIGNAL_API env & Rename to DEVICE_API to make clear distinction between CLOUD_API and DEVICE_API. * feat(ui): Only show Cloud API URL Change on device mode * fix(cloud): Don't override the CloudURL on deregistration from the cloud.
1 parent de5403e commit 7304e6b

22 files changed

+201
-113
lines changed

cloud.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func handleCloudRegister(c *gin.Context) {
9696
}
9797

9898
config.CloudToken = tokenResp.SecretToken
99-
config.CloudURL = req.CloudAPI
10099

101100
provider, err := oidc.NewProvider(c, "https://accounts.google.com")
102101
if err != nil {
@@ -298,8 +297,8 @@ func rpcDeregisterDevice() error {
298297
// (e.g., wrong cloud token, already deregistered). Regardless of the reason, we can safely remove it.
299298
if resp.StatusCode == http.StatusNotFound || (resp.StatusCode >= 200 && resp.StatusCode < 300) {
300299
config.CloudToken = ""
301-
config.CloudURL = ""
302300
config.GoogleIdentity = ""
301+
303302
if err := SaveConfig(); err != nil {
304303
return fmt.Errorf("failed to save configuration after deregistering: %w", err)
305304
}

jsonrpc.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,33 @@ func rpcSetSerialSettings(settings SerialSettings) error {
730730
return nil
731731
}
732732

733+
func rpcSetCloudUrl(url string) error {
734+
if url == "" {
735+
// Reset to default by removing from config
736+
config.CloudURL = defaultConfig.CloudURL
737+
} else {
738+
config.CloudURL = url
739+
}
740+
741+
if err := SaveConfig(); err != nil {
742+
return fmt.Errorf("failed to save config: %w", err)
743+
}
744+
return nil
745+
}
746+
747+
func rpcGetCloudUrl() (string, error) {
748+
return config.CloudURL, nil
749+
}
750+
751+
func rpcResetCloudUrl() error {
752+
// Reset to default by removing from config
753+
config.CloudURL = defaultConfig.CloudURL
754+
if err := SaveConfig(); err != nil {
755+
return fmt.Errorf("failed to reset cloud URL: %w", err)
756+
}
757+
return nil
758+
}
759+
733760
var rpcHandlers = map[string]RPCHandler{
734761
"ping": {Func: rpcPing},
735762
"getDeviceID": {Func: rpcGetDeviceID},
@@ -786,4 +813,7 @@ var rpcHandlers = map[string]RPCHandler{
786813
"setATXPowerAction": {Func: rpcSetATXPowerAction, Params: []string{"action"}},
787814
"getSerialSettings": {Func: rpcGetSerialSettings},
788815
"setSerialSettings": {Func: rpcSetSerialSettings, Params: []string{"settings"}},
816+
"setCloudUrl": {Func: rpcSetCloudUrl, Params: []string{"url"}},
817+
"getCloudUrl": {Func: rpcGetCloudUrl},
818+
"resetCloudUrl": {Func: rpcResetCloudUrl},
789819
}

ui/.env.cloud-development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# No need for VITE_CLOUD_APP it's only needed for the device build
2+
3+
# We use this for all the cloud API requests from the browser
4+
VITE_CLOUD_API=http://localhost:3000

ui/.env.cloud-production

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# No need for VITE_CLOUD_APP it's only needed for the device build
2+
3+
# We use this for all the cloud API requests from the browser
4+
VITE_CLOUD_API=https://api.jetkvm.com

ui/.env.cloud-staging

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# No need for VITE_CLOUD_APP it's only needed for the device build
2+
3+
# We use this for all the cloud API requests from the browser
4+
VITE_CLOUD_API=https://staging-api.jetkvm.com

ui/.env.development

Lines changed: 0 additions & 6 deletions
This file was deleted.

ui/.env.device

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
VITE_SIGNAL_API= # Uses the KVM device's IP address as the signal API endpoint
2-
3-
VITE_CLOUD_APP=https://app.jetkvm.com
4-
VITE_CLOUD_API=https://api.jetkvm.com
5-
6-
VITE_JETKVM_HEAD=<script src="/device/ui-config.js"></script>
1+
# Used in settings page to know where to link to when user wants to adopt a device to the cloud
2+
VITE_CLOUD_APP=http://localhost:5173

ui/.env.production

Lines changed: 0 additions & 6 deletions
This file was deleted.

ui/.env.staging

Lines changed: 0 additions & 4 deletions
This file was deleted.

ui/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<title>JetKVM</title>
2929
<link rel="stylesheet" href="/fonts/fonts.css" />
3030
<link rel="icon" href="/favicon.png" />
31-
%VITE_JETKVM_HEAD%
3231
<script>
3332
// Initial theme setup
3433
document.documentElement.classList.toggle(

0 commit comments

Comments
 (0)