Skip to content

Commit 96595eb

Browse files
author
tddlerya
committed
允许跨域访问
1 parent 79aa687 commit 96595eb

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strconv"
77
"strings"
88

9+
"github.com/gin-contrib/cors"
910
"github.com/gin-gonic/gin"
1011
"github.com/toddlerya/fakerfactory/faker"
1112
)
@@ -15,6 +16,7 @@ var Conn *sql.DB = faker.CreateConn(dbPath) // 不应该在这里建立连接,
1516

1617
func StartServer() {
1718
router := gin.Default()
19+
router.Use(cors.Default()) // 允许任何服务ajax跨域调用
1820
v1 := router.Group("api/v1")
1921
{
2022
v1.GET("/fakerfactory", GetFaker)

0 commit comments

Comments
 (0)