-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
69 lines (53 loc) · 1.32 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
67
68
69
package main
import (
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/pprof"
"github.com/gofiber/template/html"
"github.com/unownone/go-chat/app/chat"
"github.com/unownone/go-chat/routes"
)
func main() {
go chat.HubRunner()
app := fiber.New(*getConfig())
app.Use(pprof.New())
api := app.Group("/api", routes.GetNextMiddleWare)
// cors & logging
app.Use(cors.New(*getCorsConfig()))
// static
app.Static("/static", "./static")
// ********************************************
// Routes
// ********************************************
//Index Routes HTML
routes.Index("/", app)
// Auth Routes
routes.Auth("/auth", api)
// Chat Routes
routes.Chat("/chat", api)
// 404 defualt status
app.Use(get404)
app.Listen(os.Getenv("HOST") + ":" + os.Getenv("PORT"))
}
func getConfig() *fiber.Config {
return &fiber.Config{
Prefork: false, // Disable Prefork as need only 1 instance running
ServerHeader: "iMon",
AppName: "Go-Chat",
Immutable: true,
Views: getHandler(),
}
}
func getHandler() *html.Engine {
handler := html.New("./views", ".html")
return handler
}
func getCorsConfig() *cors.Config {
return &cors.Config{
AllowCredentials: true,
}
}
func get404(c *fiber.Ctx) error {
return c.SendStatus(404)
}