-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (46 loc) · 1.35 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/SohamRatnaparkhi/blogx-backend-go/authentication/pkg/handlers/server"
"github.com/SohamRatnaparkhi/blogx-backend-go/authentication/pkg/routers"
"github.com/go-chi/chi"
"github.com/go-chi/cors"
"github.com/joho/godotenv"
)
// @title Authentication server
// @description This is the authentication server for blogx
// @BasePath /v1/api
// @host 127.0.0.1:8000
func main() {
godotenv.Load(".env")
PORT := os.Getenv("PORT")
if PORT == "" {
log.Println("No PORT found")
}
router := chi.NewRouter()
router.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"https://*", "http://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: false,
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))
v1Router := chi.NewRouter()
router.Mount("/v1", v1Router)
v1Router.Get("/health", server.HealthCheck)
apiRouter := routers.SetAllRouters()
v1Router.Mount("/api", apiRouter)
fmt.Printf("\nAuthentication server starting at http://localhost:%v\n", PORT)
server := &http.Server{
Handler: router,
Addr: ":" + PORT,
}
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}