Skip to content

Commit

Permalink
Added headers to config for fixing ase.in.tum
Browse files Browse the repository at this point in the history
  • Loading branch information
SebiWrn committed Apr 22, 2024
1 parent f5b7bd7 commit 65db3fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tools/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ type Config struct {
Host string `yaml:"host"`
ApiKey string `yaml:"apiKey"`
} `yaml:"meili"`
VodURLTemplate string `yaml:"vodURLTemplate"`
CanonicalURL string `yaml:"canonicalURL"`
VodURLTemplate string `yaml:"vodURLTemplate"`
CanonicalURL string `yaml:"canonicalURL"`
Headers []Header `yaml:"headers"`
}

type MailConfig struct {
Expand All @@ -180,6 +181,11 @@ type MailConfig struct {
MaxMailsPerMinute int `yaml:"maxMailsPerMinute"`
}

type Header struct {
Header string `yaml:"header"`
Value string `yaml:"value"`
}

func (Config) GetJWTKey() *rsa.PrivateKey {
return jwtKey
}
Expand Down
9 changes: 9 additions & 0 deletions tools/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ type JWTClaims struct {
SamlSubjectID *string // identifier of the SAML session (if any)
}

func AddResponseHeaders() gin.HandlerFunc {
return func(c *gin.Context) {
for _, h := range Cfg.Headers {
c.Header(h.Header, h.Value)
}
c.Next()
}
}

func InitContext(daoWrapper dao.DaoWrapper) gin.HandlerFunc {
return func(c *gin.Context) {
// no context initialisation required for static assets.
Expand Down
1 change: 1 addition & 0 deletions web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func configMainRoute(router *gin.Engine) {

// watch
streamGroup.Use(tools.InitStream(daoWrapper))
streamGroup.Use(tools.AddResponseHeaders())
streamGroup.GET("/w/:slug/:streamID", routes.WatchPage)
streamGroup.GET("/w/:slug/:streamID/:version", routes.WatchPage)
streamGroup.GET("/w/:slug/:streamID/chat/popup", routes.PopOutChat)
Expand Down

0 comments on commit 65db3fc

Please sign in to comment.