This commit is contained in:
jinnrry committed 2023-08-13 14:00:06 +08:00
1 parent 09cdf3e697
commit f2a943f9df
5 files changed
+44 -16

No files matched your search

+3 -2
View File
@@ -11,7 +11,7 @@ import (
var IsInit bool
type Config struct {
LogLevel string `json:"logLevel"`
LogLevel string `json:"logLevel"` // 日志级别
Domain string `json:"domain"`
WebDomain string `json:"webDomain"`
DkimPrivateKeyPath string `json:"dkimPrivateKeyPath"`
@@ -25,6 +25,7 @@ type Config struct {
WeChatPushTemplateId string `json:"weChatPushTemplateId"`
WeChatPushUserId string `json:"weChatPushUserId"`
IsInit bool `json:"isInit"`
HttpsEnabled int `json:"httpsEnabled"` //后台页面是否启用https,0默认(启用),1启用,2不启用
Tables map[string]string `json:"-"`
TablesInitData map[string]string `json:"-"`
}
@@ -32,7 +33,7 @@ type Config struct {
//go:embed tables/*
var tableConfig embed.FS
const Version = "2.0.0"
const Version = "2.0.1"
const DBTypeMySQL = "mysql"
const DBTypeSQLite = "sqlite"
+2 -1
View File
@@ -12,5 +12,6 @@
"weChatPushSecret": "",
"weChatPushTemplateId": "",
"weChatPushUserId": "",
"isInit": false
"isInit": false,
"httpsEnabled": 0
}
+23 -1
View File
@@ -2,8 +2,11 @@ package http_server
import (
"fmt"
"io/fs"
"net/http"
"pmail/config"
"pmail/controllers"
"pmail/controllers/email"
"time"
)
@@ -20,7 +23,26 @@ func HttpStop() {
func HttpStart() {
mux := http.NewServeMux()
mux.HandleFunc("/", controllers.Interceptor)
if config.Instance.HttpsEnabled != 2 {
mux.HandleFunc("/", controllers.Interceptor)
} else {
fe, err := fs.Sub(local, "dist")
if err != nil {
panic(err)
}
mux.Handle("/", http.FileServer(http.FS(fe)))
mux.HandleFunc("/api/ping", contextIterceptor(controllers.Ping))
mux.HandleFunc("/api/login", contextIterceptor(controllers.Login))
mux.HandleFunc("/api/group", contextIterceptor(controllers.GetUserGroup))
mux.HandleFunc("/api/email/list", contextIterceptor(email.EmailList))
mux.HandleFunc("/api/email/detail", contextIterceptor(email.EmailDetail))
mux.HandleFunc("/api/email/send", contextIterceptor(email.Send))
mux.HandleFunc("/api/settings/modify_password", contextIterceptor(controllers.ModifyPassword))
mux.HandleFunc("/attachments/", contextIterceptor(controllers.GetAttachments))
mux.HandleFunc("/attachments/download/", contextIterceptor(controllers.Download))
}
httpServer = &http.Server{
Addr: fmt.Sprintf(":%d", HttpPort),
Handler: mux,
+12 -11
View File
@@ -62,17 +62,18 @@ func HttpsStart() {
// go http server会打一堆没用的日志,写一个空的日志处理器,屏蔽掉日志输出
nullLog := olog.New(&nullWrite{}, "", olog.Ldate)
httpsServer = &http.Server{
Addr: fmt.Sprintf(":%d", HttpsPort),
Handler: session.Instance.LoadAndSave(mux),
ReadTimeout: time.Second * 60,
WriteTimeout: time.Second * 60,
ErrorLog: nullLog,
}
err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key")
if err != nil {
panic(err)
if config.Instance.HttpsEnabled != 2 {
httpsServer = &http.Server{
Addr: fmt.Sprintf(":%d", HttpsPort),
Handler: session.Instance.LoadAndSave(mux),
ReadTimeout: time.Second * 60,
WriteTimeout: time.Second * 60,
ErrorLog: nullLog,
}
err = httpsServer.ListenAndServeTLS("config/ssl/public.crt", "config/ssl/private.key")
if err != nil {
panic(err)
}
}
}