Implement CORS headers

This commit is contained in:
Lukas SP 2020-08-23 20:29:18 +02:00
parent bfe9c5b628
commit 215315af14
1 changed files with 9 additions and 2 deletions

View File

@ -58,8 +58,15 @@ func Serve() error {
// Serve the web resources
address := env.Get("WEB_ADDRESS", ":8080")
return (&fasthttp.Server{
Handler: router.Handler,
Logger: new(nilLogger),
Handler: func(ctx *fasthttp.RequestCtx) {
// Add the CORS headers
ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET,POST,DELETE,OPTIONS")
ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
// Call the router handler
router.Handler(ctx)
},
Logger: new(nilLogger),
}).ListenAndServe(address)
}