Created
April 17, 2021 03:31
-
-
Save mxro/e8766e81cd13930aa56bc753b1cae8c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"github.com/gin-contrib/cors" | |
"github.com/gin-gonic/gin" | |
) | |
func CreateServer() *gin.Engine { | |
r := gin.Default() | |
corsEnv := os.Getenv("CORS") | |
if corsEnv != "" { | |
config := cors.DefaultConfig() | |
config.AllowOrigins = []string{corsEnv} | |
r.Use(cors.New(config)) | |
} | |
r.GET("/status", func(c *gin.Context) { | |
c.JSON(200, gin.H{ | |
"status": "ok", | |
}) | |
}) | |
return r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment