-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
45 lines (41 loc) · 1.3 KB
/
server.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
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/csrf"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/utils"
"github.com/gofiber/helmet/v2"
"log"
"loundry/api/src/database"
"loundry/api/src/routing"
"os"
"time"
)
func main() {
database.ConnectDb()
app := fiber.New()
routing.SetupRoutes(app)
app.Use(helmet.New())
csrfConfig := csrf.Config{
KeyLookup: "header:X-Csrf-Token", // string in the form of '<source>:<key>' that is used to extract token from the request
CookieName: "my_csrf_", // name of the session cookie
CookieSameSite: "Strict", // indicates if CSRF cookie is requested by SameSite
Expiration: 3 * time.Hour, // expiration is the duration before CSRF token will expire
KeyGenerator: utils.UUID, // creates a new CSRF token
}
app.Use(csrf.New(csrfConfig))
file, err := os.OpenFile("./access.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer file.Close()
// Set config for logger
//loggerConfig := logger.Config{
// Output: file, // add file to save output
//}
// Use middlewares for each route
app.Use(
logger.New(), // add Logger middleware with config
)
app.Listen(":8000")
}