Skip to content

Instantly share code, notes, and snippets.

@mxro

mxro/server.go

Created Apr 17, 2021
Embed
What would you like to do?
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