From 4170ffb5ce3a09334ec65dcfd3f7aaabd68ceb44 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker <cat@ophivana.moe> Date: Sat, 19 Oct 2024 22:54:41 +0900 Subject: [PATCH] feat(conf): do not insert CORS middleware if ALLOWED_URL is "unset" This allows easy disablement of CORS for testing. Signed-off-by: Ophestra Umiker <cat@ophivana.moe> --- app.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index bfdbcc1..345e264 100644 --- a/app.go +++ b/app.go @@ -17,10 +17,14 @@ func serve(sig chan os.Signal, db *leveldb.DB) error { app := fiber.New() // cors - app.Use(cors.New(cors.Config{ - AllowOrigins: []string{conf[allowedURL]}, - AllowHeaders: []string{"Origin", "Content-Type", "Accept"}, - })) + if conf[allowedURL] != "unset" { + app.Use(cors.New(cors.Config{ + AllowOrigins: []string{conf[allowedURL]}, + AllowHeaders: []string{"Origin", "Content-Type", "Accept"}, + })) + } else { + log.Println("CORS disabled") + } var captcha fiber.Handler hCaptchaEnable := conf[hCaptchaSiteKey] != "unset" && conf[hCaptchaSecretKey] != "unset" -- GitLab