Commit 29ec24a3 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Move static file hosting to client server, if enabled

parent 07356613
...@@ -127,17 +127,8 @@ func (s *Server) ClientHandler() http.Handler { ...@@ -127,17 +127,8 @@ func (s *Server) ClientHandler() http.Handler {
router.Use(cors.New(corsOptions).Handler) router.Use(cors.New(corsOptions).Handler)
router.Mount("/irma/", s.irmaserv.HandlerFunc()) router.Mount("/irma/", s.irmaserv.HandlerFunc())
if s.conf.StaticPath != "" { if s.conf.StaticPath != "" {
url := s.conf.URL[:len(s.conf.URL)-6] + s.conf.StaticPrefix router.Mount(s.conf.StaticPrefix, s.StaticFilesHandler())
s.conf.Logger.Infof("Hosting files at %s under %s", s.conf.StaticPath, url)
middleware.DefaultLogger = middleware.RequestLogger(&middleware.DefaultLogFormatter{
Logger: log.New(s.conf.Logger.WriterLevel(logrus.TraceLevel), "static: ", 0),
NoColor: true,
})
router.Mount(s.conf.StaticPrefix,
http.StripPrefix(s.conf.StaticPrefix, middleware.Logger(http.FileServer(http.Dir(s.conf.StaticPath)))),
)
} }
return router return router
...@@ -152,6 +143,9 @@ func (s *Server) Handler() http.Handler { ...@@ -152,6 +143,9 @@ func (s *Server) Handler() http.Handler {
if !s.conf.separateClientServer() { if !s.conf.separateClientServer() {
// Mount server for irmaclient // Mount server for irmaclient
router.Mount("/irma/", s.irmaserv.HandlerFunc()) router.Mount("/irma/", s.irmaserv.HandlerFunc())
if s.conf.StaticPath != "" {
router.Mount(s.conf.StaticPrefix, s.StaticFilesHandler())
}
} }
// Server routes // Server routes
...@@ -170,6 +164,17 @@ func (s *Server) Handler() http.Handler { ...@@ -170,6 +164,17 @@ func (s *Server) Handler() http.Handler {
return router return router
} }
func (s *Server) StaticFilesHandler() http.Handler {
url := s.conf.URL[:len(s.conf.URL)-6] + s.conf.StaticPrefix
s.conf.Logger.Infof("Hosting files at %s under %s", s.conf.StaticPath, url)
// Hook up chi middleware logger with our own logger
middleware.DefaultLogger = middleware.RequestLogger(&middleware.DefaultLogFormatter{
Logger: log.New(s.conf.Logger.WriterLevel(logrus.TraceLevel), "static: ", 0),
NoColor: true,
})
return http.StripPrefix(s.conf.StaticPrefix, middleware.Logger(http.FileServer(http.Dir(s.conf.StaticPath))))
}
func (s *Server) handleCreate(w http.ResponseWriter, r *http.Request) { func (s *Server) handleCreate(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment