Fix webapp config generator, add federation
This commit is contained in:
parent
c1d7f700c4
commit
fb32fa151c
@ -128,7 +128,7 @@ func (app *CortezaApp) mountHttpRoutes(r chi.Router) {
|
||||
}()
|
||||
|
||||
if app.Opt.HTTPServer.WebappEnabled {
|
||||
r.Route("/"+webappBaseUrl, webapp.MakeWebappServer(app.Opt.HTTPServer))
|
||||
r.Route("/"+webappBaseUrl, webapp.MakeWebappServer(app.Opt.HTTPServer, app.Opt.Federation))
|
||||
|
||||
app.Log.Info(
|
||||
"client web applications enabled",
|
||||
|
||||
@ -12,18 +12,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func MakeWebappServer(opt options.HTTPServerOpt) func(r chi.Router) {
|
||||
func MakeWebappServer(opt options.HTTPServerOpt, fed options.FederationOpt) func(r chi.Router) {
|
||||
// Serves static files directly from FS
|
||||
return func(r chi.Router) {
|
||||
fileserver := http.FileServer(http.Dir(opt.WebappBaseDir))
|
||||
|
||||
for _, app := range strings.Split(opt.WebappList, ",") {
|
||||
basedir := path.Join(opt.WebappBaseUrl, app)
|
||||
serveConfig(r, basedir, opt.ApiBaseUrl)
|
||||
serveConfig(r, basedir, opt.ApiBaseUrl, fed.Enabled)
|
||||
r.Get(basedir+"*", serveIndex(opt.WebappBaseDir, basedir, fileserver))
|
||||
}
|
||||
|
||||
serveConfig(r, opt.WebappBaseUrl, opt.ApiBaseUrl)
|
||||
serveConfig(r, opt.WebappBaseUrl, opt.ApiBaseUrl, fed.Enabled)
|
||||
r.Get(opt.WebappBaseUrl+"*", serveIndex(opt.WebappBaseDir, opt.WebappBaseUrl, fileserver))
|
||||
}
|
||||
}
|
||||
@ -65,11 +65,15 @@ func serveIndex(assetPath string, indexPath string, serve http.Handler) http.Han
|
||||
}
|
||||
}
|
||||
|
||||
func serveConfig(r chi.Router, appUrl, apiBaseUrl string) {
|
||||
func serveConfig(r chi.Router, appUrl, apiBaseUrl string, fedEnabled bool) {
|
||||
r.Get(strings.TrimRight(appUrl, "/")+"/config.js", func(w http.ResponseWriter, r *http.Request) {
|
||||
const line = "window.%sAPI = '%s/%s';\n"
|
||||
_, _ = fmt.Fprintf(w, line, "System", apiBaseUrl, "system")
|
||||
_, _ = fmt.Fprintf(w, line, "Messaging", apiBaseUrl, "messaging")
|
||||
_, _ = fmt.Fprintf(w, line, "Compose", apiBaseUrl, "compose")
|
||||
|
||||
if fedEnabled {
|
||||
_, _ = fmt.Fprintf(w, line, "Federation", apiBaseUrl, "federation")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user