Skip to content

Commit a0155ab

Browse files
authored
Merge pull request #134 from codex-team/allow-cors
Add CORS
2 parents 7798a5b + 5391a62 commit a0155ab

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/server/errorshandler/handler_sentry.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import (
1313
const SentryQueueName = "external/sentry"
1414
const CatcherType = "external/sentry"
1515

16+
// helper for CORS
17+
func allowCORS(ctx *fasthttp.RequestCtx) {
18+
h := &ctx.Response.Header
19+
h.Set("Access-Control-Allow-Origin", "*")
20+
h.Set("Access-Control-Allow-Methods", "POST, OPTIONS")
21+
h.Set("Access-Control-Allow-Headers", "Content-Type, X-Sentry-Auth")
22+
h.Set("Access-Control-Max-Age", "86400")
23+
}
24+
1625
// HandleHTTP processes HTTP requests with JSON body
1726
func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
1827
if ctx.Request.Header.ContentLength() > handler.MaxErrorCatcherMessageSize {
@@ -21,6 +30,12 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
2130
return
2231
}
2332

33+
allowCORS(ctx)
34+
if string(ctx.Method()) == fasthttp.MethodOptions {
35+
ctx.SetStatusCode(fasthttp.StatusNoContent) // 204
36+
return
37+
}
38+
2439
var hawkToken string
2540
var err error
2641

0 commit comments

Comments
 (0)