@@ -13,6 +13,8 @@ import (
13
13
"github.com/rs/cors"
14
14
"log"
15
15
"net/http"
16
+ "os"
17
+ "path/filepath"
16
18
"strconv"
17
19
)
18
20
@@ -61,18 +63,32 @@ func main() {
61
63
router .Handle ("/query" , srv )
62
64
router .Handle ("/gitconvexapi" , srv )
63
65
66
+ execName , _ := os .Executable ()
67
+ var (
68
+ staticPath string
69
+ buildPath string
70
+ )
71
+ if execName != "" {
72
+ currentDir := filepath .Dir (execName )
73
+ buildPath = fmt .Sprintf ("%s/build" , currentDir )
74
+ staticPath = fmt .Sprintf ("%s/static" , buildPath )
75
+ }
76
+
64
77
// Static file supplier for hosting the react static assets and scripts
65
- router .PathPrefix ("/static" ).Handler (http .StripPrefix ("/static" , http .FileServer (http .Dir ("./build/static/" ))))
78
+ logger .Log (fmt .Sprintf ("Serving static files from -> %s" , staticPath ), global .StatusInfo )
79
+ router .PathPrefix ("/static" ).Handler (http .StripPrefix ("/static" , http .FileServer (http .Dir (staticPath ))))
66
80
67
81
// Route for serving the webpage logo from the reach build bundle
68
82
router .PathPrefix ("/gitconvex.png" ).HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
69
- http .ServeFile (w , r , "./build/gitconvex.png" )
83
+ logger .Log (fmt .Sprintf ("Serving logo from directory -> %s" , buildPath ), global .StatusInfo )
84
+ http .ServeFile (w , r , buildPath + "/gitconvex.png" )
70
85
})
71
86
72
87
// A default fallback route for handling all routes with '/' prefix.
73
88
// For making it compatible with react router
74
89
router .PathPrefix ("/" ).HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
75
- http .ServeFile (w , r , "./build/index.html" )
90
+ logger .Log (fmt .Sprintf ("Serving UI from directory -> %s" , buildPath ), global .StatusInfo )
91
+ http .ServeFile (w , r , buildPath + "/index.html" )
76
92
})
77
93
78
94
// Checking and Assigning port received from the command line ( --port args )
0 commit comments