Skip to content

Commit

Permalink
Serve index.html under /
Browse files Browse the repository at this point in the history
We are mounting the assets filesystem under / so index.html will be
automatically served when opening the home page.
  • Loading branch information
boreq authored and mixmix committed Nov 6, 2022
1 parent 51b5f54 commit 492710e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
25 changes: 0 additions & 25 deletions web/handlers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ func New(
m.Get(router.OpenModeCreateInvite).HandlerFunc(r.HTML("admin/invite-created.tmpl", ih.createOpenMode))

// static assets

m.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(web.Assets)))

// TODO: doesnt work because of of mainMux wrapper, see issue #35
Expand All @@ -375,12 +374,6 @@ func New(

// hook up main stdlib mux to the gorrilla/mux with named routes
// TODO: issue #35

http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))

m.PathPrefix("/test").HandlerFunc(IndexHandler2("../../web/assets/index.html"))
m.PathPrefix("/").HandlerFunc(IndexHandler("../../web/assets/index.html"))

mainMux.Handle("/", m)

consumeURL := urlTo(router.CompleteInviteConsume)
Expand Down Expand Up @@ -431,21 +424,3 @@ func concatTemplates(lst ...[]string) []string {
}
return catted
}

func IndexHandler2(entrypoint string) func(w http.ResponseWriter, r *http.Request) {
fn := func(w http.ResponseWriter, r *http.Request) {
// fmt.Fprint(w, web.Assets)
http.ServeFile(w, r, entrypoint)
}

return http.HandlerFunc(fn)
}

func IndexHandler(entrypoint string) func(w http.ResponseWriter, r *http.Request) {
fn := func(w http.ResponseWriter, r *http.Request) {
// fmt.Fprint(w, web.Assets)
http.ServeFile(w, r, entrypoint)
}

return http.HandlerFunc(fn)
}
15 changes: 3 additions & 12 deletions web/router/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package router

import (
"github.com/gorilla/mux"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web"
"net/http"
)

// constant names for the named routes
Expand Down Expand Up @@ -44,8 +46,6 @@ func CompleteApp() *mux.Router {
Auth(m)
Admin(m.PathPrefix("/admin").Subrouter())

// m.Path("/").Methods("GET").Name(CompleteIndex)

m.Path("/alias/{alias}").Methods("GET").Name(CompleteAliasResolve)

m.Path("/members/change-password").Methods("GET").Name(MembersChangePasswordForm)
Expand All @@ -63,16 +63,7 @@ func CompleteApp() *mux.Router {
m.Path("/set-language").Methods("POST").Name(CompleteSetLanguage)

// Catch-all: Serve our JavaScript application's entry-point (index.html).

// m.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(web.Assets)))
m.Path("/").Handler(http.FileServer(web.Assets))

return m
}

// func HealthCheck(w http.ResponseWriter, r *http.Request) {
// fmt.Fprint(w, "API is alive and ready")
// }

// func handle(w http.ResponseWriter, r *http.Request) {
// http.Redirect(w, r, "/notice/list", http.StatusMovedPermanently)
// }

0 comments on commit 492710e

Please sign in to comment.