-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (39 loc) · 1.05 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"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"github.com/joho/godotenv"
apirouter "github.com/kwamekyeimonies/Rss-Aggregator/api_router"
)
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal(err)
}
serverPort := os.Getenv("PORT")
if serverPort == "" {
log.Fatal("PORT is not found in the Environment")
}
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 maj
}))
router.Route("/api",apirouter.ApiRouter)
server := http.Server{
Handler: router,
Addr: ":" + serverPort,
}
log.Printf("Server running on port: %v\n", serverPort)
err = server.ListenAndServe()
if err != nil {
log.Fatal(err.Error())
}
}