-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
69 lines (56 loc) · 1.53 KB
/
Copy pathserver.go
File metadata and controls
69 lines (56 loc) · 1.53 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
65
66
67
68
69
package main
import (
"log"
"os"
"resqiar.com-server/config"
"resqiar.com-server/db"
"resqiar.com-server/libs"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/joho/godotenv"
)
func main() {
// Load env variables from .env file
godotenv.Load()
server := fiber.New()
// Setup CORS
server.Use(cors.New(cors.Config{
AllowOrigins: os.Getenv("CORS_CLIENT_URL"),
AllowHeaders: "Origin, Content-Type, Accept",
AllowCredentials: true,
}))
// Setup rate-limiter
server.Use(limiter.New(config.RateLimiterConfig()))
// Setup compression
server.Use(compress.New(compress.Config{
Level: 2, // best compression
}))
// Setup caching
// server.Use(cache.New(cache.Config{
// Next: func(c *fiber.Ctx) bool {
// URL := string(c.Request().URI().Path())
// return libs.ShouldNotCached(URL)
// },
// Expiration: 30 * time.Minute,
// CacheControl: true,
// }))
DB := db.InitDB() // init Postgres db
db.InitRedis() // init Redis db
// Initialize sessions
config.InitSession()
config.InitStateSession()
// Initialize repo, service, handler and route layers
libs.ModuleInit(server, DB)
PORT := os.Getenv("PORT")
if os.Getenv("ENV") != "prod" {
if err := server.Listen(":" + PORT); err != nil {
log.Fatal(err)
}
} else {
if err := server.ListenTLS(":443", os.Getenv("PUBLIC_CERT_PATH"), os.Getenv("PRIVATE_CERT_PATH")); err != nil {
log.Fatal(err)
}
}
}