Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Nov 14, 2018
1 parent 51c2bc7 commit f97be82
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 1.2.1
VERSION = 1.2.2

APP := http-file-server
PACKAGES := $(shell go list -f {{.Dir}} ./...)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ Or [download a binary](https://github.com/sgreben/http-file-server/releases/late

```sh
# Linux
curl -L https://github.com/sgreben/http-file-server/releases/download/1.2.1/http-file-server_1.2.1_linux_x86_64.tar.gz | tar xz
curl -L https://github.com/sgreben/http-file-server/releases/download/1.2.2/http-file-server_1.2.2_linux_x86_64.tar.gz | tar xz

# OS X
curl -L https://github.com/sgreben/http-file-server/releases/download/1.2.1/http-file-server_1.2.1_osx_x86_64.tar.gz | tar xz
curl -L https://github.com/sgreben/http-file-server/releases/download/1.2.2/http-file-server_1.2.2_osx_x86_64.tar.gz | tar xz

# Windows
curl -LO https://github.com/sgreben/http-file-server/releases/download/1.2.1/http-file-server_1.2.1_windows_x86_64.zip
unzip versions_1.2.1_windows_x86_64.zip
curl -LO https://github.com/sgreben/http-file-server/releases/download/1.2.2/http-file-server_1.2.2_windows_x86_64.zip
unzip versions_1.2.2_windows_x86_64.zip
```

## Use it
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func server(addr string, routes routes) error {
log.Printf("serving local path %q on %q", path, route)
}

if _, ok := handlers[rootRoute]; !ok && len(routes.Values) > 0 {
_, rootRouteTaken := handlers[rootRoute]
if !rootRouteTaken {
route := routes.Values[0].Route
mux.Handle(rootRoute, http.RedirectHandler(route, http.StatusTemporaryRedirect))
log.Printf("redirecting to %q from %q", route, rootRoute)
Expand Down
6 changes: 5 additions & 1 deletion routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (fv *routes) Set(v string) error {
}
i := strings.Index(v, separator)
var route, path string
var err error
if i <= 0 {
path = strings.TrimPrefix(v, "=")
var err error
path, err = filepath.Abs(path)
if err != nil {
return err
Expand All @@ -43,6 +43,10 @@ func (fv *routes) Set(v string) error {
} else {
route = v[:i]
path = v[i+len(separator):]
path, err = filepath.Abs(path)
if err != nil {
return err
}
if !strings.HasPrefix(route, "/") {
route = "/" + route
}
Expand Down

0 comments on commit f97be82

Please sign in to comment.