New cookie key and updated readme

This commit is contained in:
cyp0633 2022-09-20 17:14:15 +08:00
parent b3d565b08a
commit 55d5d50d16
Signed by: cyp0633
GPG Key ID: CF90D09FB1FDCE45
3 changed files with 13 additions and 12 deletions

View File

@ -18,7 +18,7 @@ import (
func Setup() {
r := gin.Default() // 创建 Gin 实例
store := cookie.NewStore([]byte("secret")) // 使用 cookie 存储 session
store := cookie.NewStore([]byte(models.ServerConf.CookieAuth)) // 使用 cookie 存储 session
// r.StaticFS(path.Join(""), http.FS(frontend.FS)) // 服务静态文件
r.Use(cors.New(cors.Config{
@ -36,8 +36,8 @@ func Setup() {
r.Use(frontendHandler) // 先经过 handler 判断是否为前端请求
api := r.Group("/api") // 设置 API 路由组
api.Use(sessions.Sessions("mysession", store)) // 设置 Gin 中间件
api := r.Group("/api") // 设置 API 路由组
api.Use(sessions.Sessions("k12mathsession", store)) // 设置 Gin 中间件
api.GET("/ping", func(c *gin.Context) { // 测试 API
c.JSON(200, gin.H{

View File

@ -22,7 +22,8 @@ var SMSConf = struct {
// ServerConf 配置服务器的端口号等信息。
var ServerConf = struct {
Port string // 服务器端口号
Port string // 服务器端口号
CookieAuth string // Cookie Auth Key
}{}
// InitConf 使用文件夹内的 conf.ini 文件初始化配置。CLI 无需此操作。
@ -46,5 +47,6 @@ func InitConf() {
serverSection := cfg.Section("server")
{
ServerConf.Port = serverSection.Key("port").String()
ServerConf.CookieAuth = serverSection.Key("cookie_auth").String()
}
}

View File

@ -13,14 +13,12 @@
1. 下载 Go SDK 1.19 及之后版本、Node.js 最新 LTS、yarn
2. 进入 frontend 目录
3. 备份 frontend/dist/frontend.go 文件
4. 执行 `yarn build` 命令
5. 恢复 frontend/dist/frontend.go 文件
6. 进入 cmd/server 目录
7. 执行 `go build` 命令
8. 创建 conf.ini 文件
9. 运行编译出的 `server` 可执行文件
10. 打开 `http://localhost:8000`
3. 执行 `yarn build` 命令
4. 进入 cmd/server 目录
5. 执行 `go build` 命令
6. 创建 conf.ini 文件,填入对应的数据
7. 运行编译出的 `server` 可执行文件
8. 打开 `http://localhost:port`,其中 port 为 conf.ini 中的端口号
## 配置文件格式
@ -37,4 +35,5 @@ access_key_secret = "阿里云短信服务 AccessKeySecret"
[server]
port = 8000 # 服务器端口
cookie_auth = "cookie 加密密钥"
```