fix(api): ko json content type
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
162adfbe16
commit
451735d261
20
api/api.go
20
api/api.go
@ -189,7 +189,7 @@ func (api *API) registerWebAppRoutes(router *gin.Engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) registerKOAPIRoutes(apiGroup *gin.RouterGroup) {
|
func (api *API) registerKOAPIRoutes(apiGroup *gin.RouterGroup) {
|
||||||
koGroup := apiGroup.Group("/ko")
|
koGroup := apiGroup.Group("/ko", koJSONMiddleware)
|
||||||
|
|
||||||
// KO sync routes (webapp uses - progress & activity)
|
// KO sync routes (webapp uses - progress & activity)
|
||||||
koGroup.GET("/documents/:document/file", api.authKOMiddleware, api.createDownloadDocumentHandler(apiErrorPage))
|
koGroup.GET("/documents/:document/file", api.authKOMiddleware, api.createDownloadDocumentHandler(apiErrorPage))
|
||||||
@ -325,6 +325,13 @@ func (api *API) loadTemplates(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) templateMiddleware(router *gin.Engine) gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
router.HTMLRender = *api.generateTemplates()
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func loggingMiddleware(c *gin.Context) {
|
func loggingMiddleware(c *gin.Context) {
|
||||||
// Start timer
|
// Start timer
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
@ -361,9 +368,12 @@ func loggingMiddleware(c *gin.Context) {
|
|||||||
log.WithFields(logData).Info(fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.Path))
|
log.WithFields(logData).Info(fmt.Sprintf("%s %s", c.Request.Method, c.Request.URL.Path))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) templateMiddleware(router *gin.Engine) gin.HandlerFunc {
|
// koJSONMiddleware forces JSON Content-Type to only return `application/json`. This is addressing
|
||||||
return func(c *gin.Context) {
|
// the following issue: https://github.com/koreader/koreader/issues/13629
|
||||||
router.HTMLRender = *api.generateTemplates()
|
func koJSONMiddleware(c *gin.Context) {
|
||||||
c.Next()
|
c.Next()
|
||||||
|
contentType := c.Writer.Header().Get("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "application/json") {
|
||||||
|
c.Header("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user