diff --git a/server/main.go b/server/main.go index bc7499f..3c768c4 100644 --- a/server/main.go +++ b/server/main.go @@ -4,9 +4,10 @@ import ( "fmt" "io/fs" "net/http" - "os" "strings" + // Importing web package + "github.com/EnjoyBacon7/cbFiles/web" // Importing handlers package "github.com/EnjoyBacon7/cbFiles/server/handlers" ) @@ -84,8 +85,9 @@ func serveFileContents(file string, files http.FileSystem) http.HandlerFunc { // ------------------------------------------------------------ // Main Go Routing Logic // ------------------------------------------------------------ + func main() { - var frontend fs.FS = os.DirFS("./web/build") + var frontend fs.FS = web.GetUiFs() httpFS := http.FS(frontend) fileServer := http.FileServer(httpFS) serveIndex := serveFileContents("index.html", httpFS) diff --git a/web/embed.go b/web/embed.go new file mode 100644 index 0000000..a9bd630 --- /dev/null +++ b/web/embed.go @@ -0,0 +1,20 @@ +package web + +import ( + "embed" + "io/fs" + "os" +) + +//go:embed build +var Embedded_reactApp embed.FS + +func GetUiFs() fs.FS { + //embedRoot, err := fs.Sub(EMBED_UI, "ui") + embedRoot, err := fs.Sub(Embedded_reactApp, "build") + if err != nil { + os.Exit(1) + } + return embedRoot + // return http.FileServer(http.FS(embedRoot)) +} \ No newline at end of file diff --git a/web/src/components/CbFiles.js b/web/src/components/CbFiles.js index 7992cf8..0f85ed6 100644 --- a/web/src/components/CbFiles.js +++ b/web/src/components/CbFiles.js @@ -141,7 +141,7 @@ function handleIconPath(fileName) { function handleDelete(shareId, fileName, loadFiles) { var request = new XMLHttpRequest(); - request.open('DELETE', `/api/delete?shareId=${shareId}&fileName=${fileName}`, true); + request.open('DELETE', `/api/delete?shareId=${encodeURIComponent(shareId)}&fileName=${encodeURIComponent(fileName)}`, true); request.onload = function () { if (request.status >= 200 && request.status < 400) { loadFiles(); @@ -154,7 +154,7 @@ function handleDelete(shareId, fileName, loadFiles) { function handleDownload(shareId, fileName) { var request = new XMLHttpRequest(); - request.open('GET', `/api/download?shareId=${shareId}&fileName=${fileName}`, true); + request.open('GET', `/api/download?shareId=${encodeURIComponent(shareId)}&fileName=${encodeURIComponent(fileName)}`, true); request.responseType = 'blob'; request.onload = function () { if (request.status >= 200 && request.status < 400) {