2021-03-13 23:06:03 +08:00
|
|
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
2020-10-20 21:57:29 +08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/astaxie/beego"
|
2021-05-07 20:51:29 +08:00
|
|
|
"github.com/astaxie/beego/logs"
|
2020-10-20 21:57:29 +08:00
|
|
|
"github.com/astaxie/beego/plugins/cors"
|
2021-08-01 00:30:12 +08:00
|
|
|
_ "github.com/astaxie/beego/session/redis"
|
2021-07-25 09:34:25 +08:00
|
|
|
"github.com/casbin/casdoor/authz"
|
|
|
|
"github.com/casbin/casdoor/controllers"
|
|
|
|
"github.com/casbin/casdoor/object"
|
|
|
|
"github.com/casbin/casdoor/routers"
|
2020-10-20 21:57:29 +08:00
|
|
|
|
2021-07-25 09:34:25 +08:00
|
|
|
_ "github.com/casbin/casdoor/routers"
|
2020-10-20 21:57:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-10-20 23:14:03 +08:00
|
|
|
object.InitAdapter()
|
2021-02-15 10:05:14 +08:00
|
|
|
object.InitDb()
|
2021-02-14 00:22:24 +08:00
|
|
|
controllers.InitHttpClient()
|
2021-02-28 20:23:50 +08:00
|
|
|
authz.InitAuthz()
|
2020-10-20 23:14:03 +08:00
|
|
|
|
2020-10-20 21:57:29 +08:00
|
|
|
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
|
|
|
|
AllowOrigins: []string{"*"},
|
|
|
|
AllowMethods: []string{"GET", "PUT", "PATCH"},
|
|
|
|
AllowHeaders: []string{"Origin"},
|
|
|
|
ExposeHeaders: []string{"Content-Length"},
|
|
|
|
AllowCredentials: true,
|
|
|
|
}))
|
|
|
|
|
2020-10-20 23:24:07 +08:00
|
|
|
//beego.DelStaticPath("/static")
|
|
|
|
beego.SetStaticPath("/static", "web/build/static")
|
2021-03-29 23:40:25 +08:00
|
|
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
|
|
|
beego.SetStaticPath("/swagger", "swagger")
|
2020-10-20 23:24:07 +08:00
|
|
|
// https://studygolang.com/articles/2303
|
2021-02-28 20:23:50 +08:00
|
|
|
beego.InsertFilter("*", beego.BeforeRouter, routers.StaticFilter)
|
2021-03-28 16:35:59 +08:00
|
|
|
beego.InsertFilter("*", beego.BeforeRouter, routers.AutoLoginFilter)
|
2021-02-28 20:23:50 +08:00
|
|
|
beego.InsertFilter("*", beego.BeforeRouter, routers.AuthzFilter)
|
2021-07-07 14:59:03 +08:00
|
|
|
beego.InsertFilter("*", beego.BeforeRouter, routers.RecordMessage)
|
2020-10-20 23:24:07 +08:00
|
|
|
|
2021-03-06 00:19:06 +08:00
|
|
|
beego.BConfig.WebConfig.Session.SessionName = "casdoor_session_id"
|
2021-08-01 00:30:12 +08:00
|
|
|
if beego.AppConfig.String("redisEndpoint") == "" {
|
|
|
|
beego.BConfig.WebConfig.Session.SessionProvider = "file"
|
|
|
|
beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp"
|
|
|
|
} else {
|
|
|
|
beego.BConfig.WebConfig.Session.SessionProvider = "redis"
|
|
|
|
beego.BConfig.WebConfig.Session.SessionProviderConfig = beego.AppConfig.String("redisEndpoint")
|
|
|
|
}
|
|
|
|
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 30
|
2021-02-14 21:21:42 +08:00
|
|
|
//beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode
|
2020-10-20 21:57:29 +08:00
|
|
|
|
2021-05-07 20:51:29 +08:00
|
|
|
err := logs.SetLogger("file", `{"filename":"logs/casdoor.log","maxdays":99999}`)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
logs.SetLevel(logs.LevelInformational)
|
|
|
|
logs.SetLogFuncCall(false)
|
|
|
|
|
2020-10-20 21:57:29 +08:00
|
|
|
beego.Run()
|
|
|
|
}
|