Override CORS, query apis from client

This commit is contained in:
sid palas
2023-01-23 15:06:40 -05:00
parent 22ad01e315
commit 961c90cd7b
15 changed files with 268 additions and 17 deletions

View File

@ -3,7 +3,9 @@ package main
import (
"log"
"os"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"api-golang/database"
@ -22,10 +24,25 @@ func init() {
func main() {
r := gin.Default()
r.Use(cors.New(cors.Config{
// AllowOrigins: []string{"http://127.0.0.1:5173/"},
AllowMethods: []string{"GET"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
// AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
// return origin == "http://127.0.0.1:8080/"
},
// MaxAge: 12 * time.Hour,
}))
var tm time.Time
r.GET("/", func(c *gin.Context) {
database.GetTime(c)
tm = database.GetTime(c)
c.JSON(200, gin.H{
"message": "pong",
"api": "golang",
"now": tm,
})
})
r.Run() // listen and serve on 0.0.0.0:8080