2 Commits

Author SHA1 Message Date
zero@thinky 398c688fed fix race
ci-agent / build (push) Failing after 2m42s
2026-04-04 18:15:45 +03:00
zero@thinky 958211198c feat(backend): add cors 2026-04-04 17:53:35 +03:00
5 changed files with 38 additions and 1 deletions
+1
View File
@@ -130,6 +130,7 @@ func main() {
}
router := gin.Default()
router.Use(handlers.CorsMiddleware("http://127.0.0.1:5173;http://localhost:5173"))
docs.SwaggerInfo.BasePath = "/api/v1"
docs.SwaggerInfo.Title = "HellreigN"
docs.SwaggerInfo.Version = "1.0"
+1
View File
@@ -6,6 +6,7 @@ require (
gitea.d3m0k1d.ru/d3m0k1d/HellreigN/proto v0.0.0-20260403210401-a6212c89fc0e
github.com/ClickHouse/clickhouse-go/v2 v2.44.0
github.com/gin-gonic/gin v1.12.0
github.com/samber/lo v1.53.0
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.1
github.com/swaggo/swag v1.16.6
+2
View File
@@ -138,6 +138,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/samber/lo v1.53.0 h1:t975lj2py4kJPQ6haz1QMgtId2gtmfktACxIXArw3HM=
github.com/samber/lo v1.53.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0=
github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
@@ -81,6 +81,7 @@ func (self *Agent) AddJob(job models.JobForInsert) (int64, error) {
if err != nil {
return 0, err
}
self.jobs[jid] = newJob()
self.in <- &proto.Command{
Id: jid,
Command: job.Command,
@@ -155,7 +156,6 @@ func (self *Agent) recv() error {
func (self *Agent) send() error {
for job := range self.in {
self.jobs[job.Id] = newJob()
if err := self.bidi.Send(job); err != nil {
return err
}
+33
View File
@@ -0,0 +1,33 @@
package handlers
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/samber/lo"
)
func CorsMiddleware(origincfg string) gin.HandlerFunc {
origins := strings.Split(origincfg, ";")
if origins[0] == "" {
panic("zero cors origins wtf is your config")
}
return func(c *gin.Context) {
origin := c.GetHeader("Origin")
if !lo.Contains(origins, origin) {
origin = origins[0]
}
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
// c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, Authorization")
c.Writer.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PATCH, DELETE, PUT")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}
}