Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (app *App) loadConfiguration() error {
return nil
}

//OnErrorHandler handles panics
// OnErrorHandler handles panics
func (app *App) OnErrorHandler(err error, stack []byte) {
app.Logger.Error(
"Panic occurred.",
Expand Down Expand Up @@ -343,7 +343,7 @@ func (app *App) createLeaderboardClient() lservice.Leaderboard {
return leaderboardService
}

//AddError rate statistics
// AddError rate statistics
func (app *App) AddError() {
app.Errors.Update(1)
}
Expand Down Expand Up @@ -463,7 +463,7 @@ func (app *App) startHTTPServer(ctx context.Context, lis net.Listener) error {
}

mux := http.NewServeMux()
mux.Handle("/", removeTrailingSlashMiddleware{addVersionMiddleware{gatewayMux}})
mux.Handle("/", removeTrailingSlashMiddleware{addVersionMiddleware{addCorsMiddleware{gatewayMux}}})
mux.HandleFunc("/healthcheck", addVersionHandlerFunc(app.healthCheckHandler))
mux.HandleFunc("/status", addVersionHandlerFunc(app.statusHandler))
attachSpan := func(span opentracing.Span, r *http.Request) {
Expand Down
33 changes: 32 additions & 1 deletion api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (app *App) loggerMiddleware(ctx context.Context, req interface{}, info *grp
return h, err
}

//Serve executes on error handler when errors happen
// Serve executes on error handler when errors happen
func (app *App) recoveryMiddleware(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
defer func() {
if err := recover(); err != nil {
Expand Down Expand Up @@ -197,3 +197,34 @@ func (m removeTrailingSlashMiddleware) ServeHTTP(w http.ResponseWriter, r *http.
r.URL.Path = m.removeTrailingSlash(r.URL.Path)
m.Handler.ServeHTTP(w, r)
}

type addCorsMiddleware struct {
Handler http.Handler
}

func addCorsHeaders(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*")
/*
w.Header().Set("Vary", "Origin")
w.Header().Set("Vary", "Access-Control-Request-Method")
w.Header().Set("Vary", "Access-Control-Request-Headers")
*/
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
w.Header().Set("Access-Control-Allow-Methods", "GET,PATCH,POST,PUT,OPTIONS,DELETE")
}

func (m addCorsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
addCorsHeaders(w)
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
} else {
m.Handler.ServeHTTP(w, r)
}
}

func addCorsHandlerFunc(f func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
addCorsHeaders(w)
f(w, r)
}
}
4 changes: 2 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# http://www.opensource.org/licenses/mit-license
# Copyright © 2019 Top Free Games <backend@tfgco.com>

FROM golang:1.16.3-alpine as build
FROM golang:1.17-alpine as build

MAINTAINER TFG Co <backend@tfgco.com>

Expand All @@ -21,4 +21,4 @@ COPY --from=build /podium/config/default.yaml /default.yaml

RUN chmod +x /podium

ENTRYPOINT ["/podium", "-c", "/default.yaml"]
ENTRYPOINT ["/podium", "-c", "/default.yaml", "start"]
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/topfreegames/extensions v8.0.2+incompatible h1:4LMv5SBpep8WkUVGmgpGg0TYzYfydWktrh1YW60KAwU=
github.com/topfreegames/extensions v8.0.2+incompatible/go.mod h1:VbIAks7aNbkANieZyVShAV3FSxEbV6useS4r3neXVzc=
github.com/uber/jaeger-client-go v2.25.0+incompatible h1:IxcNZ7WRY1Y3G4poYlx24szfsn/3LvK9QHCq9oQw8+U=
github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-client-go v2.29.1+incompatible h1:R9ec3zO3sGpzs0abd43Y+fBZRJ9uiH6lXyR/+u6brW4=
github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg=
Expand Down