overflow_server_app/main.go
crusader 1639b86706 ing
2017-11-23 17:06:44 +09:00

58 lines
1.6 KiB
Go

package main
import (
"flag"
cc "git.loafle.net/commons_go/config"
"git.loafle.net/commons_go/cors_fasthttp"
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_server_app/config"
"git.loafle.net/overflow/overflow_server_app/external"
"git.loafle.net/overflow/overflow_server_app/module/member"
"git.loafle.net/overflow/overflow_server_app/server"
"github.com/valyala/fasthttp"
)
func init() {
configPath := flag.String(ConfigPathFlagName, "./", "The path of config file")
flag.Parse()
cc.SetConfigPath(*configPath)
if err := cc.Load(&config.Config, ConfigFileName); nil != err {
panic(err)
}
}
func main() {
defer logging.Logger().Sync()
external.ExternalInit()
s := server.New()
s.Route("POST", "/account/signin", member.SignIn)
s.Route("POST", "/account/signup", member.SignUp)
s.Route("POST", "/account/forgot_password", member.ForgotPassword)
s.Route("POST", "/account/reset_password", member.ResetPassword)
s.Route("GET", "/account/check_email", member.CheckEmail)
c := cors_fasthttp.AllowAll()
fasthttp.ListenAndServe(config.Config.Server.Addr, c.Handler(s.Handler))
external.ExternalDestroy()
}
//
//func CORS(next server.RequestHandler) server.RequestHandler {
// return server.RequestHandler(func(sctx *server.ServerContext, ctx * fasthttp.RequestCtx) {
//
// ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true" )
// ctx.Response.Header.Set("Access-Control-Allow-Headers", "authorization")
// ctx.Response.Header.Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,DELETE,OPTIONS" )
// ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
//
// next(sctx, ctx)
// })
//}