Skip to content

Blank page when using Gzip middleware #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mangaldev opened this issue Sep 21, 2019 · 5 comments
Closed

Blank page when using Gzip middleware #19

mangaldev opened this issue Sep 21, 2019 · 5 comments

Comments

@mangaldev
Copy link

I use gzip middleware as it is needed for faster througput, but on using it swagger doesnt work.

@mangaldev
Copy link
Author

Turned out we can skip the middleware only for swagger.

e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
		Skipper: func(c echo.Context) bool {
			if strings.Contains(c.Request().URL.Path, "swagger") {
				return true
			}
			return false
		},
	}))

bilal-kilic added a commit to bilal-kilic/echo-swagger that referenced this issue Nov 4, 2019
Added the solution to problem with blank page when using gzip to documents for better visibility swaggoGH-19
@covert8
Copy link

covert8 commented Dec 9, 2019

Hi I'm using a dependency that enables gzip middleware. Is there an other workaround?
What specifically causes this behaviour, so I have a clue where to look to fix it.

@wantdrink
Copy link

I have the same issue and commented in #3,

@Nexucis
Copy link

Nexucis commented Mar 8, 2021

On my side, I didn't want to change the gzip configuration. So I ended up by manually creating the route required. Here is a piece of code for others that don't want to change the gzip config as well:

import (
	"net/http"

	"github.com/labstack/echo/v4"
	"github.com/swaggo/files"
)

type Endpoint struct {
}

func (e *Endpoint) RegisterRoutes(g *echo.Group) {
	g.GET("/favicon-16x16.png", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "image/png", swaggerFiles.FileFavicon16x16Png)
	})
	g.GET("/favicon-32x32.png", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "image/png", swaggerFiles.FileFavicon32x32Png)
	})
	g.GET("/swagger-ui.css", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/css", swaggerFiles.FileSwaggerUICSS)
	})
	g.GET("/swagger-ui.css.map", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/css", swaggerFiles.FileSwaggerUICSSMap)
	})
	g.GET("/index.html", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/html; charset=UTF-8", []byte(indexTempl))
	})
	g.GET("/doc.json", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "application/json; charset=UTF-8", []byte(docAPI.Swagger))
	})
	g.GET("/swagger-ui.js", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIJs)
	})
	g.GET("/swagger-ui.js.map", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIJsMap)
	})
	g.GET("/swagger-ui-bundle.js", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIBundleJs)
	})
	g.GET("/swagger-ui-bundle.js.map", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIBundleJsMap)
	})
	g.GET("/swagger-ui-standalone-preset.js", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIStandalonePresetJs)
	})
	g.GET("/swagger-ui-standalone-preset.js.map", func(c echo.Context) error {
		return c.Blob(http.StatusOK, "text/javascript", swaggerFiles.FileSwaggerUIStandalonePresetJsMap)
	})
}

kesuskim added a commit to kesuskim/echo-swagger that referenced this issue Aug 31, 2021
@kesuskim
Copy link
Contributor

This seems with gzip middleware somehow flush does not work, so manually doing flush works OK.
I made patch for this.

ubogdan pushed a commit that referenced this issue Oct 12, 2021
Added the solution to problem with blank page when using gzip to documents for better visibility GH-19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants