casnode/main.go

69 lines
2.3 KiB
Go
Raw Permalink Normal View History

// Copyright 2021 The casbin Authors. All Rights Reserved.
2020-05-31 18:56:59 +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 (
2021-08-26 00:22:28 +08:00
"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
_ "github.com/astaxie/beego/session/redis"
"github.com/casbin/casnode/casdoor"
"github.com/casbin/casnode/object"
"github.com/casbin/casnode/routers"
"github.com/casbin/casnode/service"
"github.com/casbin/casnode/util"
2020-05-31 18:56:59 +08:00
)
func main() {
2020-05-31 23:02:22 +08:00
object.InitAdapter()
2021-09-06 01:13:13 +08:00
object.InitHttpClient()
casdoor.InitCasdoorAdapter()
2021-08-25 23:47:22 +08:00
service.InitDictionary()
util.InitSegmenter()
object.InitForumBasicInfo()
object.InitFrontConf()
2021-08-26 00:22:28 +08:00
object.InitTimer()
2020-05-31 23:02:22 +08:00
2020-05-31 18:56:59 +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,
}))
2022-08-09 20:10:21 +08:00
// beego.DelStaticPath("/static")
2020-06-01 00:26:51 +08:00
beego.SetStaticPath("/static", "web/build/static")
beego.SetStaticPath("/swagger", "swagger")
beego.BConfig.WebConfig.DirectoryIndex = true
2020-06-01 00:26:51 +08:00
// https://studygolang.com/articles/2303
2021-08-15 20:29:58 +08:00
beego.InsertFilter("*", beego.BeforeRouter, routers.BotFilter)
beego.InsertFilter("*", beego.BeforeRouter, routers.Static)
2021-08-15 21:56:38 +08:00
beego.InsertFilter("*", beego.BeforeRouter, routers.AutoSigninFilter)
2020-06-01 00:26:51 +08:00
2023-12-30 16:06:53 +08:00
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.WebConfig.Session.SessionName = "casnode_session_id"
if beego.AppConfig.String("redisEndpoint") == "" {
2021-08-03 00:52:19 +08:00
beego.BConfig.WebConfig.Session.SessionProvider = "file"
beego.BConfig.WebConfig.Session.SessionProviderConfig = "./tmp"
} else {
beego.BConfig.WebConfig.Session.SessionProvider = "redis"
2023-12-30 16:06:53 +08:00
beego.BConfig.WebConfig.Session.SessionProviderConfig = beego.AppConfig.String("redisEndpoint")
2021-08-03 00:52:19 +08:00
}
2023-12-30 16:06:53 +08:00
beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600 * 24 * 365
2020-05-31 18:56:59 +08:00
2021-08-26 00:22:28 +08:00
beego.Run()
2020-05-31 18:56:59 +08:00
}