This commit is contained in:
@@ -10,7 +10,10 @@ import (
|
||||
"tomatentum.net/svg-templater/pkg/svg"
|
||||
)
|
||||
|
||||
var mux http.ServeMux
|
||||
|
||||
func PrepareHTTP() {
|
||||
mux = *http.NewServeMux()
|
||||
registerAuthorizedFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "You are authorized!")
|
||||
})
|
||||
@@ -51,13 +54,14 @@ func PrepareHTTP() {
|
||||
|
||||
func Start() {
|
||||
log.Println("Starting http server on :3000")
|
||||
if err := http.ListenAndServe(":3000", nil); err != nil {
|
||||
handler := corsMiddleware(&mux)
|
||||
if err := http.ListenAndServe(":3000", handler); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func registerAuthorized(path string, handler http.Handler) {
|
||||
http.HandleFunc(path, auth.AuthMiddleware(handler))
|
||||
mux.HandleFunc(path, auth.AuthMiddleware(handler))
|
||||
log.Println("Registered authorized handler for", path)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user