diff --git a/docker-compose.yml b/docker-compose.yml
index e657390a..a9d00967 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -30,11 +30,14 @@ services:
# - SQL_DSN=root:123456@tcp(mysql:3306)/new-api # Point to the mysql service, uncomment if using MySQL
- REDIS_CONN_STRING=redis://redis
- TZ=Asia/Shanghai
- - ERROR_LOG_ENABLED=true # 是否启用错误日志记录
- - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 batch update enabled
-# - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions
-# - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! multi-node deployment, set this to a random string!!!!!!!
+ - ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
+ - BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
+# - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
+# - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! (multi-node deployment, set this to a random string!!!!!!!)
# - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
+# - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
+# - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
+# - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL,默认为官方地址 (Umami Script URL, defaults to official URL)
depends_on:
- redis
diff --git a/main.go b/main.go
index 47f71a20..481d0a60 100644
--- a/main.go
+++ b/main.go
@@ -150,6 +150,26 @@ func main() {
})
server.Use(sessions.Sessions("session", store))
+ InjectUmamiAnalytics()
+ InjectGoogleAnalytics()
+
+ // 设置路由
+ router.SetRouter(server, buildFS, indexPage)
+ var port = os.Getenv("PORT")
+ if port == "" {
+ port = strconv.Itoa(*common.Port)
+ }
+
+ // Log startup success message
+ common.LogStartupSuccess(startTime, port)
+
+ err = server.Run(":" + port)
+ if err != nil {
+ common.FatalLog("failed to start HTTP server: " + err.Error())
+ }
+}
+
+func InjectUmamiAnalytics() {
analyticsInjectBuilder := &strings.Builder{}
if os.Getenv("UMAMI_WEBSITE_ID") != "" {
umamiSiteID := os.Getenv("UMAMI_WEBSITE_ID")
@@ -164,21 +184,28 @@ func main() {
analyticsInjectBuilder.WriteString("\">")
}
analyticsInject := analyticsInjectBuilder.String()
- indexPage = bytes.ReplaceAll(indexPage, []byte("