Skip to content

Commit

Permalink
API默认允许跨域
Browse files Browse the repository at this point in the history
  • Loading branch information
nyancatda committed Sep 21, 2022
1 parent 0a6a25b commit fce2b40
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Routers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: NyanCatda
* @Date: 2022-06-20 13:12:12
* @LastEditTime: 2022-06-28 17:01:33
* @LastEditTime: 2022-09-21 12:16:52
* @LastEditors: NyanCatda
* @Description: 路由注册
* @FilePath: \MCBE-Server-Motd\Routers.go
Expand All @@ -18,6 +18,7 @@ import (
"github.com/BlackBEDevelopment/MCBE-Server-Motd/StatusImg"
cache "github.com/chenyahui/gin-cache"
"github.com/chenyahui/gin-cache/persist"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/nyancatda/AyaLog"
)
Expand All @@ -38,6 +39,12 @@ func SetupRouter(r *gin.Engine) *gin.Engine {
// 注册前端页面
FrontendRouter(r)

// 注册跨域请求头
CorsConfig := cors.DefaultConfig()
CorsConfig.AllowOrigins = []string{"*"}
CorsConfig.AllowHeaders = []string{"*"}
r.Use(cors.New(CorsConfig))

// 基岩版查询API
r.GET("/api", func(c *gin.Context) {
Host := c.Query("host")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/BlackBEDevelopment/MCBE-Server-Motd
go 1.17

require (
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.8.1
github.com/nyancatda/AyaLog v1.0.6
github.com/nyancatda/AyaLog/ModLog/GinLog v0.0.0-20220606093827-834efb2bcb30
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
Expand Down Expand Up @@ -93,8 +95,6 @@ github.com/nyancatda/AyaLog v1.0.6 h1:q3ado58lN1diMlUJoqTW2ck5OpyqTxH71SaCyOIlm1
github.com/nyancatda/AyaLog v1.0.6/go.mod h1:ZbOWddB8xUfSdNuDAvfpTe76EGgOp1XaGouCTh+J+1w=
github.com/nyancatda/AyaLog/ModLog/GinLog v0.0.0-20220606093827-834efb2bcb30 h1:CW0an87co464JMGXhW3GGtfwD1ZJfagz+baiCxI4nvc=
github.com/nyancatda/AyaLog/ModLog/GinLog v0.0.0-20220606093827-834efb2bcb30/go.mod h1:OJBSMsNqE0XjWJewYs/1ZK80UcNu58fD0bwrfy7HgaA=
github.com/nyancatda/AyaLog/TimedTask v0.0.0-20220623153654-e4e69037a75a h1:JMwy1nKX0746PRY6H1D27wS75NIQOqEZrBb5b4/5mC8=
github.com/nyancatda/AyaLog/TimedTask v0.0.0-20220623153654-e4e69037a75a/go.mod h1:wA7G2fQ3YKPNuAIYtAZbefWOlK8EULUZ3lcTpviwHP4=
github.com/nyancatda/AyaLog/TimedTask v0.0.0-20220627152527-68e778cd1741 h1:c3L11WeKQy0Jj1qjB7MtvwJIfOqbcd5A3UiqNULvK8s=
github.com/nyancatda/AyaLog/TimedTask v0.0.0-20220627152527-68e778cd1741/go.mod h1:wA7G2fQ3YKPNuAIYtAZbefWOlK8EULUZ3lcTpviwHP4=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand All @@ -117,14 +117,16 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: NyanCatda
* @Date: 2021-12-05 22:27:13
* @LastEditTime: 2022-06-23 23:39:57
* @LastEditTime: 2022-09-21 12:18:03
* @LastEditors: NyanCatda
* @Description:
* @FilePath: \MCBE-Server-Motd\main.go
Expand Down Expand Up @@ -33,7 +33,9 @@ func main() {
go TimedTask.Start()

// 关闭Gin默认的日志输出
gin.DefaultWriter = ioutil.Discard
if !*DeBug {
gin.DefaultWriter = ioutil.Discard
}

// 初始化Gin
gin.SetMode(gin.ReleaseMode)
Expand Down

0 comments on commit fce2b40

Please sign in to comment.