|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"io/fs"
|
|
|
|
"io/fs"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
|
@ -30,8 +31,6 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) routes() http.Handler {
|
|
|
|
func (app *application) routes() http.Handler {
|
|
|
|
router := httprouter.New()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
staticDir, _ := fs.Sub(ui.Files, "static")
|
|
|
|
staticDir, _ := fs.Sub(ui.Files, "static")
|
|
|
|
|
|
|
|
|
|
|
|
staticData, ok := staticDir.(fs.ReadDirFS)
|
|
|
|
staticData, ok := staticDir.(fs.ReadDirFS)
|
|
|
@ -41,6 +40,14 @@ func (app *application) routes() http.Handler {
|
|
|
|
|
|
|
|
|
|
|
|
fileServer := statigz.FileServer(staticData, brotli.AddEncoding, statigz.EncodeOnInit)
|
|
|
|
fileServer := statigz.FileServer(staticData, brotli.AddEncoding, statigz.EncodeOnInit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router := httprouter.New()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { app.notFound(w) })
|
|
|
|
|
|
|
|
router.PanicHandler = func(w http.ResponseWriter, _ *http.Request, err interface{}) {
|
|
|
|
|
|
|
|
w.Header().Set("Connection", "close")
|
|
|
|
|
|
|
|
app.serverError(w, fmt.Errorf("%s", err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
router.Handler(http.MethodGet, "/", http.RedirectHandler("/motions/", http.StatusMovedPermanently))
|
|
|
|
router.Handler(http.MethodGet, "/", http.RedirectHandler("/motions/", http.StatusMovedPermanently))
|
|
|
|
router.Handler(
|
|
|
|
router.Handler(
|
|
|
|
http.MethodGet,
|
|
|
|
http.MethodGet,
|
|
|
@ -50,14 +57,14 @@ func (app *application) routes() http.Handler {
|
|
|
|
router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))
|
|
|
|
router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))
|
|
|
|
router.HandlerFunc(http.MethodGet, "/motions/", app.motionList)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/motions/", app.motionList)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/motions/:tag", app.motionDetails)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/motions/:tag", app.motionDetails)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodGet, "/vote/:tag", app.voteForm)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodPost, "/vote/:tag", app.voteSubmit)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodGet, "/proxy/:tag", app.proxyVoteForm)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodPost, "/proxy/:tag", app.proxyVoteSubmit)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/newmotion/", app.newMotionForm)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/newmotion/", app.newMotionForm)
|
|
|
|
router.HandlerFunc(http.MethodPost, "/newmotion/", app.newMotionSubmit)
|
|
|
|
router.HandlerFunc(http.MethodPost, "/newmotion/", app.newMotionSubmit)
|
|
|
|
router.HandlerFunc(http.MethodGet, "/vote/", app.voteForm)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodPost, "/vote/", app.voteSubmit)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodGet, "/proxy/", app.proxyVoteForm)
|
|
|
|
|
|
|
|
router.HandlerFunc(http.MethodPost, "/proxy/", app.proxyVoteSubmit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
standard := alice.New(app.recoverPanic, app.logRequest, secureHeaders)
|
|
|
|
standard := alice.New(app.logRequest, secureHeaders)
|
|
|
|
|
|
|
|
|
|
|
|
return standard.Then(router)
|
|
|
|
return standard.Then(router)
|
|
|
|
}
|
|
|
|
}
|
|
|
|