diff --git a/README.md b/README.md index 53d10c4f3..4312b78de 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,12 @@ cd ../embedg-server go run main.go migrate postgres up # Start the development server (optional) -go run main.go server +go run --tags embedapp main.go server # Build and include the frontend files in the backend binary +go build --tags embedapp + +# Build without including the frontend files in the backend binary (you need to serve yourself) go build ``` @@ -96,7 +99,6 @@ postgres: app: public_url: "http://localhost:5173/app" - server_static: true # Set to false if you don't want the serve the frontend files (you will need a HTTP server like Nginx to host it instead) api: # Make sure to add {public_url}/auth/callback to the OAuth2 Redirect URLs of your application in the Discord dev portal diff --git a/embedg-app/embed.go b/embedg-app/embed.go index e10c135c9..f44d21d19 100644 --- a/embedg-app/embed.go +++ b/embedg-app/embed.go @@ -1,3 +1,6 @@ +//go:build embedapp +// +build embedapp + package embedgapp import "embed" diff --git a/embedg-app/noembed.go b/embedg-app/noembed.go new file mode 100644 index 000000000..ce8b7b6ce --- /dev/null +++ b/embedg-app/noembed.go @@ -0,0 +1,8 @@ +//go:build !embedapp +// +build !embedapp + +package embedgapp + +import "embed" + +var DistFS embed.FS diff --git a/embedg-app/package.go b/embedg-app/package.go new file mode 100644 index 000000000..6dbcd7397 --- /dev/null +++ b/embedg-app/package.go @@ -0,0 +1 @@ +package embedgapp diff --git a/embedg-server/api/server.go b/embedg-server/api/server.go index 79317767e..6193b901a 100644 --- a/embedg-server/api/server.go +++ b/embedg-server/api/server.go @@ -40,14 +40,12 @@ func Serve() { RegisterRoutes(app, &stores{pg, bot}) - if viper.GetBool("app.serve_static") { - app.Use("/", filesystem.New(filesystem.Config{ - Root: http.FS(embedgapp.DistFS), - Browse: false, - NotFoundFile: "dist/index.html", - PathPrefix: "/dist", - })) - } + app.Use("/", filesystem.New(filesystem.Config{ + Root: http.FS(embedgapp.DistFS), + Browse: false, + NotFoundFile: "dist/index.html", + PathPrefix: "/dist", + })) go bot.Start() diff --git a/embedg-server/config/defaults.go b/embedg-server/config/defaults.go index 0c538f9b8..e7bed5307 100644 --- a/embedg-server/config/defaults.go +++ b/embedg-server/config/defaults.go @@ -13,7 +13,6 @@ func setupDefaults() { v.SetDefault("postgres.password", "") v.SetDefault("app.public_url", "http://localhost:5173/app") - v.SetDefault("app.serve_static", true) // API defaults v.SetDefault("api.host", "localhost")