-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 1.12 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
package main
import (
"log"
"example.com/go-fiber/config"
"example.com/go-fiber/database"
"example.com/go-fiber/router"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
_ "github.com/lib/pq"
)
// entry point to our program
func main() {
// Connect to database
if err := database.Connect(); err != nil {
log.Fatalf("Database connection Error: %v ", err)
}
// call the New() method - used to instantiate a new Fiber App
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowCredentials: true,
AllowOrigins: "http://localhost:3000",
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
AllowHeaders: "Content-Type, Accept, Authorization",
}))
// Middleware
app.Use(logger.New())
// Logging remote IP and Port
app.Use(logger.New(logger.Config{
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
}))
// Initialize the session store
config.InitSessionStore()
// Use the session middleware
app.Use(config.SessionMiddleware)
router.RegisterRoutes(app)
router.SetupRoutes(app)
// listen on port 5000
app.Listen(":3001")
}