Skip to content

Commit 00842ce

Browse files
committed
add fallback logic to use cwd UI bundle
1 parent 297766c commit 00842ce

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

api/settings_api.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/neel1996/gitconvex-server/utils"
99
"io/ioutil"
1010
"os"
11+
"path/filepath"
1112
)
1213

1314
var logger global.Logger
@@ -36,7 +37,14 @@ func UpdatePortNumber(newPort string) string {
3637
newEnvData.Port = newPort
3738
newEnvData.DataBaseFile = envData.DataBaseFile
3839

39-
cwd, _ := os.Getwd()
40+
execName, execErr := os.Executable()
41+
if execErr != nil {
42+
logger.Log(execErr.Error(), global.StatusError)
43+
return global.PortUpdateError
44+
}
45+
46+
cwd := filepath.Dir(execName)
47+
4048
fileString := cwd + "/" + global.EnvFileName
4149
envContent, _ := json.MarshalIndent(&newEnvData, "", " ")
4250
writeErr := ioutil.WriteFile(fileString, envContent, 0755)
@@ -61,7 +69,14 @@ func UpdateDBFilePath(newFilePath string) string {
6169
newEnvData.Port = envData.Port
6270
newEnvData.DataBaseFile = newFilePath
6371

64-
cwd, _ := os.Getwd()
72+
execName, execErr := os.Executable()
73+
if execErr != nil {
74+
logger.Log(execErr.Error(), global.StatusError)
75+
return global.DataFileUpdateError
76+
}
77+
78+
cwd := filepath.Dir(execName)
79+
6580
fileString := cwd + "/" + global.EnvFileName
6681
envContent, _ := json.MarshalIndent(&newEnvData, "", " ")
6782
writeErr := ioutil.WriteFile(fileString, envContent, 0755)

server.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ func main() {
7373
logger.Log("Unable to serve UI bundle", global.StatusError)
7474
}
7575

76+
// Setting the server to use the UI bundle from the current directory if the bundle is unavailable in the executable directory
77+
// Resolved UI file server issue when running docker containers
78+
_, uiOpenErr := os.Open(buildPath)
79+
if uiOpenErr != nil {
80+
logger.Log(uiOpenErr.Error(), global.StatusError)
81+
cwd, _ := os.Getwd()
82+
if cwd != "" {
83+
logger.Log("Using UI bundle from the current directory -> "+cwd, global.StatusInfo)
84+
buildPath = fmt.Sprintf("%s/gitconvex-ui", cwd)
85+
}
86+
}
87+
7688
// Static file supplier for hosting the react static assets and scripts
7789
logger.Log(fmt.Sprintf("Serving static files from -> %s", staticPath), global.StatusInfo)
7890
router.PathPrefix("/static").Handler(http.StripPrefix("/static", http.FileServer(http.Dir(staticPath))))

0 commit comments

Comments
 (0)