Set proxy origin
This commit is contained in:
parent
cda4924051
commit
b87fc7f7c6
5
Godeps/Godeps.json
generated
5
Godeps/Godeps.json
generated
@ -12,6 +12,11 @@
|
|||||||
"Comment": "v6.1.0-4-g6cef6a7",
|
"Comment": "v6.1.0-4-g6cef6a7",
|
||||||
"Rev": "6cef6a7f8b01a4288118f1a4c5c303f117c1c7f0"
|
"Rev": "6cef6a7f8b01a4288118f1a4c5c303f117c1c7f0"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "github.com/gin-contrib/cors",
|
||||||
|
"Comment": "v1.3.0-1-g2a8f489",
|
||||||
|
"Rev": "2a8f489b42294786cbf465c1f20588b49117f1fe"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/gin-contrib/sse",
|
"ImportPath": "github.com/gin-contrib/sse",
|
||||||
"Comment": "v0.1.0-1-g43f0f29",
|
"Comment": "v0.1.0-1-g43f0f29",
|
||||||
|
12
main.go
12
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"gitea-issue/giteaClient"
|
"gitea-issue/giteaClient"
|
||||||
"github.com/caarlos0/env"
|
"github.com/caarlos0/env"
|
||||||
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||||
@ -14,8 +15,13 @@ import (
|
|||||||
var (
|
var (
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
giteaConfig giteaClient.GiteaConfig
|
giteaConfig giteaClient.GiteaConfig
|
||||||
|
proxyConfig ProxyConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ProxyConfig struct {
|
||||||
|
ProjectOrigin string `env:"PROJECT_ORIGIN,required"`
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//open a db connection
|
//open a db connection
|
||||||
var err error
|
var err error
|
||||||
@ -26,6 +32,9 @@ func init() {
|
|||||||
if err := env.Parse(&giteaConfig); err != nil {
|
if err := env.Parse(&giteaConfig); err != nil {
|
||||||
panic("ENV error")
|
panic("ENV error")
|
||||||
}
|
}
|
||||||
|
if err := env.Parse(&proxyConfig); err != nil {
|
||||||
|
panic("ENV error")
|
||||||
|
}
|
||||||
|
|
||||||
giteaClient.SetUp(giteaConfig)
|
giteaClient.SetUp(giteaConfig)
|
||||||
db.AutoMigrate(&userModel{})
|
db.AutoMigrate(&userModel{})
|
||||||
@ -34,6 +43,9 @@ func init() {
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
config := cors.DefaultConfig()
|
||||||
|
config.AllowOrigins = []string{proxyConfig.ProjectOrigin}
|
||||||
|
router.Use(cors.New(config))
|
||||||
|
|
||||||
v1 := router.Group("/api/v1/issues")
|
v1 := router.Group("/api/v1/issues")
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user