-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (54 loc) · 1.48 KB
/
main.go
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
package main
import (
"os"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/csrf"
"github.com/gofiber/fiber/v2/middleware/encryptcookie"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/utils"
"github.com/joho/godotenv"
"github.com/returnone-x/server/config"
)
func main() {
godotenv.Load()
// init config
config.Connect()
config.GoogleOauth()
config.GithubOauth()
app := fiber.New()
// Set logger
app.Use(logger.New(logger.Config{
Format: "[${time}] ${ip} - | ${status} |${latency} | ${method} | ${path} \n",
TimeFormat: "2006/01/02 15:04:05",
TimeZone: "local",
}))
// encrypt cookie
app.Use(encryptcookie.New(encryptcookie.Config{
Except: []string{"user_id"},
Key: os.Getenv("ENCRYPT_COOKIE_SECRET"),
}))
// cors middleware setup
app.Use(cors.New(cors.Config{
AllowOrigins: "https://returnone.tech",
AllowHeaders: "Origin, Content-Type, Accept",
}))
// protection Cross-Site Request Forgery (CSRF) attacks
// *when test csrf must change the ENV*
if os.Getenv("ENV") == "production" {
app.Use(csrf.New(csrf.Config{
KeyLookup: "header:X-Csrf-Token",
CookieName: "csrf_",
CookieSameSite: "Strict",
Expiration: 15 * time.Minute,
KeyGenerator: utils.UUID,
}))
}
routes(app)
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Welcome to returnone backend!")
})
// app Listen
app.Listen(":8080")
}