-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
66 lines (50 loc) · 1.4 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"net/http"
"github.com/LeoBorquez/worki-back/config"
"github.com/LeoBorquez/worki-back/handler"
"github.com/LeoBorquez/worki-back/router"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/labstack/gommon/log"
)
var cfg = config.LoadConfig()
func main() {
app := fiber.New()
app.Use(logger.New())
router.SetupRoutes(app)
log.Fatal(app.Listen(loadPort()))
// fmt.Printf("%v, %T\n", const, const) print value and type of const
cors := cfg.Cors
log.Printf("[-] Value CORS %v\n", cfg.Cors)
// Start echo
e := echo.New()
e.Logger.SetLevel(log.ERROR)
e.Use(middleware.Logger())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{cors},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}))
e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte(handler.Key),
Skipper: func(c echo.Context) bool {
if c.Path() == "/login" || c.Path() == "/signup" {
return true
}
return false
},
}))
routes.Routes(e)
e.Logger.Fatal(e.Start(loadPort()))
}
func loadPort() string {
port := cfg.Port
if port == "" {
port = "1323"
log.Printf("[-] No Port Enviroment variable detected. Setting to ", port)
}
return ":" + port
}