diff --git a/cmd/ysvd/main.go b/cmd/ysvd/main.go index 9068d81..e78804d 100644 --- a/cmd/ysvd/main.go +++ b/cmd/ysvd/main.go @@ -62,7 +62,6 @@ YSV_DB: path to json database type config struct { Port int - Host string DB string } @@ -81,10 +80,6 @@ func main() { os.Exit(0) } } - if c.Host == "" { - log.Printf("must set YSV_HOST; please run $(ysvd env) for more information") - os.Exit(1) - } if c.DB == "" { log.Printf("warning: in-memory db mode; if you do not want this set YSV_DB") } @@ -100,7 +95,7 @@ func main() { if err := ms.Load(); err != nil { log.Printf("unable to load db: %v; creating fresh database", err) } - vain.NewServer(sm, ms, c.Host) + vain.NewServer(sm, ms) addr := fmt.Sprintf(":%d", c.Port) if err := http.ListenAndServe(addr, sm); err != nil { log.Printf("problem with http server: %v", err) diff --git a/server.go b/server.go index 738cfee..fb2164d 100644 --- a/server.go +++ b/server.go @@ -8,10 +8,9 @@ import ( ) // NewServer populates a server, adds the routes, and returns it for use. -func NewServer(sm *http.ServeMux, store Storage, hostname string) *Server { +func NewServer(sm *http.ServeMux, store Storage) *Server { s := &Server{ - storage: store, - hostname: hostname, + storage: store, } sm.Handle("/", s) return s @@ -19,8 +18,7 @@ func NewServer(sm *http.ServeMux, store Storage, hostname string) *Server { // Server serves up the http. type Server struct { - hostname string - storage Storage + storage Storage } func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { @@ -45,7 +43,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { http.Error(w, fmt.Sprintf("invalid repository %q", req.URL.Path), http.StatusBadRequest) return } - p.path = fmt.Sprintf("%s/%s", s.hostname, strings.Trim(req.URL.Path, "/")) + p.path = fmt.Sprintf("%s/%s", req.Host, strings.Trim(req.URL.Path, "/")) if !Valid(p.path, s.storage.All()) { http.Error(w, fmt.Sprintf("invalid path; prefix already taken %q", req.URL.Path), http.StatusConflict) return