-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
64 lines (52 loc) · 1.47 KB
/
main.go
File metadata and controls
64 lines (52 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package handler
import (
"log"
"net/http"
"time"
controllers "undetectable-ai/DSk/controller"
"github.com/gofiber/adaptor/v2"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/vercel/go-bridge/go/bridge"
)
var app *fiber.App
func init() {
app = setupApp()
log.Println("🚀 Initializing server...")
}
func setupApp() *fiber.App {
app := fiber.New()
app.Use(limiter.New(limiter.Config{
Max: 20,
Expiration: 1 * time.Minute,
KeyGenerator: func(c *fiber.Ctx) string {
return c.IP()
},
}))
allowedOrigins := map[string]bool{
"http://127.0.0.1:5500": true,
"https://humanize-ai-frontend.vercel.app": true, // NODE
"https://humanize-ai-one.vercel.app": true, // GO
"https://humanize-ai-server.vercel.app": true, // PY
"http://localhost:3000": true,
"http://localhost:8080": true,
}
app.Use(cors.New(cors.Config{
AllowOriginsFunc: func(origin string) bool {
return allowedOrigins[origin]
},
AllowMethods: "POST",
AllowHeaders: "Content-Type, X-API-Key",
AllowCredentials: true,
ExposeHeaders: "Content-Length",
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("🚀 Server is running on Vercel!")
})
app.Post("/rewrite", controllers.RewriteHandler)
return app
}
func Handler(w http.ResponseWriter, r *http.Request) {
bridge.Start(adaptor.FiberApp(app))
}