Macaron: Strip down renderer middleware (#37627)
* strip down macaron renderer * inline renderHTML * remove IndentJSON parameter * replace renderer with a html/template set * fix failing test * fix renderer paths in tests * make template reloading even simpler * unify ignored gzip path lookup * fix csp middleware usage
This commit is contained in:
@@ -118,7 +118,7 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
|
||||
|
||||
if err := avatar.Encode(ctx.Resp); err != nil {
|
||||
log.Warnf("avatar encode error: %v", err)
|
||||
ctx.WriteHeader(500)
|
||||
ctx.Resp.WriteHeader(500)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,10 +217,7 @@ func setupScenarioContext(t *testing.T, url string) *scenarioContext {
|
||||
require.Truef(t, exists, "Views should be in %q", viewsPath)
|
||||
|
||||
sc.m = macaron.New()
|
||||
sc.m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||
Directory: viewsPath,
|
||||
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
||||
}))
|
||||
sc.m.UseMiddleware(macaron.Renderer(viewsPath, "[[", "]]"))
|
||||
sc.m.Use(getContextHandler(t, cfg).Middleware)
|
||||
|
||||
return sc
|
||||
|
||||
@@ -58,11 +58,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT
|
||||
|
||||
m := macaron.New()
|
||||
m.Use(getContextHandler(t, cfg).Middleware)
|
||||
m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||
Directory: filepath.Join(setting.StaticRootPath, "views"),
|
||||
IndentJSON: true,
|
||||
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
||||
}))
|
||||
m.UseMiddleware(macaron.Renderer(filepath.Join(setting.StaticRootPath, "views"), "[[", "]]"))
|
||||
m.Get("/api/frontend/settings/", hs.GetFrontendSettings)
|
||||
|
||||
return m, hs
|
||||
|
||||
@@ -335,7 +335,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
|
||||
m.Use(middleware.Logger(hs.Cfg))
|
||||
|
||||
if hs.Cfg.EnableGzip {
|
||||
m.Use(middleware.Gziper())
|
||||
m.UseMiddleware(middleware.Gziper())
|
||||
}
|
||||
|
||||
m.Use(middleware.Recovery(hs.Cfg))
|
||||
@@ -354,11 +354,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
|
||||
m.SetURLPrefix(hs.Cfg.AppSubURL)
|
||||
}
|
||||
|
||||
m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||
Directory: filepath.Join(hs.Cfg.StaticRootPath, "views"),
|
||||
IndentJSON: macaron.Env != macaron.PROD,
|
||||
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
||||
}))
|
||||
m.UseMiddleware(macaron.Renderer(filepath.Join(hs.Cfg.StaticRootPath, "views"), "[[", "]]"))
|
||||
|
||||
// These endpoints are used for monitoring the Grafana instance
|
||||
// and should not be redirected or rejected.
|
||||
@@ -408,7 +404,7 @@ func (hs *HTTPServer) healthzHandler(ctx *macaron.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.WriteHeader(200)
|
||||
ctx.Resp.WriteHeader(200)
|
||||
_, err := ctx.Resp.Write([]byte("Ok"))
|
||||
if err != nil {
|
||||
hs.log.Error("could not write to response", "err", err)
|
||||
|
||||
Reference in New Issue
Block a user