forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ | |
.DS_Store | ||
.env* | ||
.tmp | ||
dist | ||
dist | ||
ui | ||
^ui/index.html |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ os: linux | |
dist: xenial | ||
language: go | ||
|
||
addons: | ||
hosts: | ||
- local.iqka.com | ||
services: | ||
- docker | ||
env: | ||
|
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/yaoapp/xiang/global" | ||
) | ||
|
||
// Middlewares 服务中间件 | ||
var Middlewares = []gin.HandlerFunc{ | ||
BindDomain, | ||
BinStatic, | ||
} | ||
|
||
// BindDomain 绑定许可域名 | ||
func BindDomain(c *gin.Context) { | ||
|
||
for _, allow := range global.AllowHosts { | ||
if strings.Contains(c.Request.Host, allow) { | ||
c.Next() | ||
return | ||
} | ||
} | ||
|
||
c.JSON(403, gin.H{ | ||
"code": 403, | ||
"message": fmt.Sprintf("%s is not allowed", c.Request.Host), | ||
}) | ||
c.Abort() | ||
} | ||
|
||
// BinStatic 静态文件服务 | ||
func BinStatic(c *gin.Context) { | ||
if len(c.Request.URL.Path) >= 5 && c.Request.URL.Path[0:5] == "/api/" { | ||
c.Next() | ||
return | ||
} | ||
|
||
// 静态文件请求 | ||
global.FileServer.ServeHTTP(c.Writer, c.Request) | ||
c.Abort() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
hello world | ||
hello world 2 |