Skip to content

Commit

Permalink
without regex
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Jul 1, 2019
1 parent cc649e2 commit eeb52ec
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions server.go
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"net/http"
"os"
"regexp"
"strings"

"github.com/gorilla/context"
Expand Down Expand Up @@ -171,8 +170,8 @@ func runMain() error {

// HTML routes
html := web.New()
// image routes
htmlImages := web.New()
// static routes
static := web.New()

// Execute various middleware functions. The order is very important
// as each function establishes part of the application environment/context
Expand All @@ -184,7 +183,7 @@ func runMain() error {
html.Use(csrf.Protect([]byte(cfg.APISecret), csrf.Secure(cfg.CookieSecure)))

// Setup static files
htmlImages.Get("/assets/*", http.StripPrefix("/assets/",
static.Get("/assets/*", http.StripPrefix("/assets/",
http.FileServer(http.Dir(cfg.PublicPath))))
html.Get("/robots.txt", http.FileServer(http.Dir(cfg.PublicPath)))
html.Get("/favicon.ico", http.FileServer(http.Dir(cfg.PublicPath+"/images")))
Expand Down Expand Up @@ -232,7 +231,7 @@ func runMain() error {
html.Post("/register", application.Route(controller, "RegisterPost"))

// Captcha
htmlImages.Get("/captchas/*", controller.CaptchaServe)
static.Get("/captchas/*", controller.CaptchaServe)
html.Post("/verifyhuman", controller.CaptchaVerify)

// Stats
Expand All @@ -248,13 +247,10 @@ func runMain() error {
// KTHXBYE
html.Get("/logout", application.Route(controller, "Logout"))

// divide routes
htmlRoutes := regexp.MustCompile(`^/(api/*|robots.txt|favicon.ico|admintickets|status|address|emailupdate|emailverify|error|passwordreset|passwordupdate|settings|login|register|verifyhuman|stats|tickets|voting|logout)?$`)
ImageRoutes := regexp.MustCompile(`^/(assets|captchas)/.*$`)

app.Handle("/api/*", api)
app.Handle(htmlRoutes, html)
app.Handle(ImageRoutes, htmlImages)
app.Handle("/assets/*", static)
app.Handle("/captchas/*", static)
app.Handle("/*", html)

graceful.PostHook(func() {
controller.RPCStop()
Expand Down

0 comments on commit eeb52ec

Please sign in to comment.