Update release script to build/distribute backend

This commit is contained in:
2020-05-03 19:19:28 +02:00
parent a9c24051b0
commit 957912c9fc
8 changed files with 179 additions and 24 deletions

View File

@ -5,9 +5,9 @@ go 1.14
require (
github.com/asdine/storm/v3 v3.1.1
github.com/caarlos0/env/v6 v6.2.1
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-chi/chi v4.1.1+incompatible
github.com/gorilla/websocket v1.4.2
github.com/gorilla/websocket v1.4.2 // indirect
github.com/pkg/errors v0.9.1
gitlab.com/wpetit/goweb v0.0.0-20200418152305-76dea96a46ce
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect

View File

@ -16,7 +16,8 @@ type Config struct {
}
type HTTPConfig struct {
Address string `yaml:"address" env:"GUESSTIMATE_HTTP_ADDRESS"`
Address string `yaml:"address" env:"GUESSTIMATE_HTTP_ADDRESS"`
PublicDir string `yaml:"publicDir" env:"GUESSTIMATE_PUBLIC_DIR"`
}
type DataConfig struct {
@ -55,7 +56,8 @@ func NewDumpDefault() *Config {
func NewDefault() *Config {
return &Config{
HTTP: HTTPConfig{
Address: ":8081",
Address: ":8081",
PublicDir: "public",
},
Data: DataConfig{
Path: "guesstimate.db",

View File

@ -1,8 +1,12 @@
package route
import (
"net/http"
"path"
"forge.cadoles.com/wpetit/guesstimate/internal/config"
"github.com/go-chi/chi"
"gitlab.com/wpetit/goweb/static"
)
func Mount(r *chi.Mux, config *config.Config) error {
@ -13,5 +17,16 @@ func Mount(r *chi.Mux, config *config.Config) error {
r.Delete("/projects/{projectID}", handleDeleteProject)
})
clientIndex := path.Join(config.HTTP.PublicDir, "index.html")
serveClientIndex := func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, clientIndex)
}
r.Get("/p/*", serveClientIndex)
notFoundHandler := r.NotFoundHandler()
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
return nil
}