add
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"user/logger"
|
||||
"user/logic"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/lib/pq"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -21,14 +23,30 @@ func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.Default()
|
||||
|
||||
// 配置跨域中间件
|
||||
r.Use(cors.New(cors.Config{
|
||||
// 允许所有来源(生产环境建议指定具体域名)
|
||||
AllowOrigins: []string{"*"},
|
||||
// 允许的请求方法
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||
// 允许的请求头
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "X-LoginRequest-ID"},
|
||||
// 允许前端读取的响应头
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
// 是否允许携带cookie
|
||||
AllowCredentials: true,
|
||||
// 预检请求的缓存时间
|
||||
MaxAge: 12 * time.Hour,
|
||||
}))
|
||||
|
||||
// 登录接口
|
||||
r.POST("/user/login", logic.LoginHandler)
|
||||
zap.L().Info("✅ 登录接口注册完成: POST /user/login")
|
||||
// 注册接口
|
||||
r.POST("/user/register", logic.RegisterHandler)
|
||||
zap.L().Info("✅ 登录接口注册完成: POST /user/register")
|
||||
zap.L().Info("✅ 注册接口注册完成: POST /user/register")
|
||||
|
||||
// 启动服务,监听80端口
|
||||
zap.L().Info("✅ 服务启动在80端口")
|
||||
r.Run(":80")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user