diff --git a/README.md b/README.md index debd7d0..81422dc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ API_PORT=8000 API_SECRET=change-me OPEN_API_ENABLED=true -OPEN_API_ENDPOINT=/docs +OPEN_API_ENDPOINT=/openapi ``` ### 2. Обязательные переменные по режимам @@ -49,7 +49,7 @@ OPEN_API_ENDPOINT=/docs - `DB_PATH=sqlite://data/app.db` - `API_HOST=localhost` - `API_PORT=8000` -- `OPEN_API_ENDPOINT=/docs` +- `OPEN_API_ENDPOINT=/openapi` ### 4. Описание переменных diff --git a/backend/src/api/server.go b/backend/src/api/server.go index bd770bf..0554f24 100644 --- a/backend/src/api/server.go +++ b/backend/src/api/server.go @@ -11,6 +11,8 @@ import ( "context" "log" "net/http" + "net/http/httptest" + "strings" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" @@ -34,9 +36,41 @@ func NewServer(cfg config.Config) *Server { log.Fatal(err) } + gin.SetMode(gin.ReleaseMode) router := gin.Default() if cfg.OpenAPIEnabled { - router.GET("/openapi/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + openAPIEndpoint := cfg.OpenAPIEndpoint + if openAPIEndpoint == "" { + openAPIEndpoint = "/openapi" + } + swaggerHandler := ginSwagger.WrapHandler(swaggerFiles.Handler) + + router.GET(openAPIEndpoint, func(c *gin.Context) { + recorder := httptest.NewRecorder() + proxyCtx, _ := gin.CreateTestContext(recorder) + proxyCtx.Request = c.Request.Clone(c.Request.Context()) + proxyCtx.Request.URL.Path = openAPIEndpoint + "/index.html" + proxyCtx.Request.RequestURI = openAPIEndpoint + "/index.html" + + swaggerHandler(proxyCtx) + + for key, values := range recorder.Header() { + for _, value := range values { + c.Writer.Header().Add(key, value) + } + } + + body := strings.Replace( + recorder.Body.String(), + "
", + "Avg. Income
+$8,107
++5.2% growth
+Avg. Expenses
+$4,603
+-12% decrease
+{{ month.month }}
+${{ month.income - month.expenses }}
+{{ (((month.income - month.expenses) / month.income) * 100).toFixed(0) }}%
+Total Balance
+Income
+$8,240
+Expenses
+$3,120
+${{ category.spent }} of ${{ category.budget }}
++ {{ category.spent > category.budget ? '+' : '' }}${{ Math.abs(category.budget - category.spent) }} +
+{{ ((category.spent / category.budget) * 100).toFixed(0) }}%
+Total Balance
+ +This Month
+$8,240
++18% income
+Expenses
+$3,120
+-8% saved
+Family budget
+Good evening
+Edit src/App.vue and save to test HMR
{{ activity.title }}
+{{ activity.subtitle }}
+Manage your family hub
+Family Admin
+john.smith@email.com
+{{ module.name }}
++ {{ module.enabled ? 'Active' : 'Disabled' }} +
+Family OS v2.4.0
+© 2026 Family Hub Inc.
+Swipe to decide
+{{ currentCard.subtitle }}
+Wednesday, April 2
+{{ transaction.title }}
++ {{ transaction.type === 'income' ? '+' : '-' }}${{ Math.abs(transaction.amount).toFixed(2) }} +
+
Connect with us
-Join the Vite community
---
-
-
- GitHub
-
-
- -
-
-
- Discord
-
-
- -
-
-
- X.com
-
-
- -
-
-
- Bluesky
-
-
-
-