Skip to content
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

refactor!: CORS support for decision service removed #487

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
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
Next Next commit
CORS middleware not registered any more
  • Loading branch information
dadrus committed Feb 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit eb219abbf416650e048b4d7a468407864cdf3fea
52 changes: 21 additions & 31 deletions internal/handler/decision/app.go
Original file line number Diff line number Diff line change
@@ -17,11 +17,8 @@
package decision

import (
"strings"

"github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
@@ -65,9 +62,12 @@ func newApp(args appArgs) *fiber.App {
JSONEncoder: json.Marshal,
})

app.Use(recover.New(recover.Config{EnableStackTrace: true}))
app.Use(tracingmiddleware.New(
tracingmiddleware.WithTracer(otel.GetTracerProvider().Tracer("github.com/dadrus/heimdall/decision"))))
app.Use(
recover.New(recover.Config{EnableStackTrace: true}),
tracingmiddleware.New(
tracingmiddleware.WithTracer(otel.GetTracerProvider().Tracer("github.com/dadrus/heimdall/decision")),
),
)

if args.Config.Metrics.Enabled {
app.Use(prometheusmiddleware.New(
@@ -76,31 +76,21 @@ func newApp(args appArgs) *fiber.App {
))
}

app.Use(accesslogmiddleware.New(args.Logger))
app.Use(loggermiddlerware.New(args.Logger))

if service.CORS != nil {
app.Use(cors.New(cors.Config{
AllowOrigins: strings.Join(service.CORS.AllowedOrigins, ","),
AllowMethods: strings.Join(service.CORS.AllowedMethods, ","),
AllowHeaders: strings.Join(service.CORS.AllowedHeaders, ","),
AllowCredentials: service.CORS.AllowCredentials,
ExposeHeaders: strings.Join(service.CORS.ExposedHeaders, ","),
MaxAge: int(service.CORS.MaxAge.Seconds()),
}))
}

app.Use(errormiddleware.New(
errormiddleware.WithVerboseErrors(service.Respond.Verbose),
errormiddleware.WithPreconditionErrorCode(service.Respond.With.ArgumentError.Code),
errormiddleware.WithAuthenticationErrorCode(service.Respond.With.AuthenticationError.Code),
errormiddleware.WithAuthorizationErrorCode(service.Respond.With.AuthorizationError.Code),
errormiddleware.WithCommunicationErrorCode(service.Respond.With.CommunicationError.Code),
errormiddleware.WithMethodErrorCode(service.Respond.With.BadMethodError.Code),
errormiddleware.WithNoRuleErrorCode(service.Respond.With.NoRuleError.Code),
errormiddleware.WithInternalServerErrorCode(service.Respond.With.InternalError.Code),
))
app.Use(cachemiddleware.New(args.Cache))
app.Use(
accesslogmiddleware.New(args.Logger),
loggermiddlerware.New(args.Logger),
errormiddleware.New(
errormiddleware.WithVerboseErrors(service.Respond.Verbose),
errormiddleware.WithPreconditionErrorCode(service.Respond.With.ArgumentError.Code),
errormiddleware.WithAuthenticationErrorCode(service.Respond.With.AuthenticationError.Code),
errormiddleware.WithAuthorizationErrorCode(service.Respond.With.AuthorizationError.Code),
errormiddleware.WithCommunicationErrorCode(service.Respond.With.CommunicationError.Code),
errormiddleware.WithMethodErrorCode(service.Respond.With.BadMethodError.Code),
errormiddleware.WithNoRuleErrorCode(service.Respond.With.NoRuleError.Code),
errormiddleware.WithInternalServerErrorCode(service.Respond.With.InternalError.Code),
),
cachemiddleware.New(args.Cache),
)

return app
}