Skip to content

Commit

Permalink
add global gzip middleware + robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
g-harel committed Jun 6, 2019
1 parent 55e3eaa commit b527c04
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions assets/robots.txt
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
5 changes: 4 additions & 1 deletion go.mod
@@ -1,3 +1,6 @@
module github.com/g-harel/npmfs

require github.com/gorilla/mux v1.7.2
require (
github.com/NYTimes/gziphandler v1.1.1
github.com/gorilla/mux v1.7.2
)
9 changes: 9 additions & 0 deletions go.sum
@@ -1,2 +1,11 @@
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I=
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5 changes: 5 additions & 0 deletions main.go
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"

"github.com/NYTimes/gziphandler"
"github.com/g-harel/npmfs/handlers"
"github.com/g-harel/npmfs/templates"
"github.com/gorilla/mux"
Expand All @@ -31,6 +32,9 @@ func redirect(pre, post string) http.HandlerFunc {
func main() {
r := mux.NewRouter()

// Add gzip middleware to all handlers.
r.Use(gziphandler.GzipHandler)

// Show homepage.
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
templates.PageHome().Render(w)
Expand All @@ -57,6 +61,7 @@ func main() {
assets := http.FileServer(http.Dir("assets"))
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", assets))
r.HandleFunc("/favicon.ico", redirect("/assets", ""))
r.HandleFunc("/robots.txt", redirect("/assets", ""))

// Attempt to match single path as package name.
// Handlers registered before this point have a higher matching priority.
Expand Down

0 comments on commit b527c04

Please sign in to comment.