-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
49 lines (37 loc) · 1012 Bytes
/
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
package main
import (
"log"
"net/http"
"os"
"time"
"cov-api/models/db"
"cov-api/routes"
"cov-api/utils"
"github.com/rs/cors"
)
var (
CURRENT_HOST = os.Getenv("CURRENT_HOST")
)
func main() {
utils.AddCronJobs(CURRENT_HOST)
db.DBCon, _ = db.CreateDatabase() // initialising the database
r := routes.GetRoutes()
// Serving Static files
fs := http.FileServer(http.Dir("./static"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"POST", "GET", "PATCH", "OPTIONS"},
AllowedHeaders: []string{"Access-Control-Allow-Origin", "Accept", "Accept-Language", "Content-Type", "Authorization"},
AllowCredentials: true,
Debug: true,
})
srv := &http.Server{
Addr: ":" + os.Getenv("PORT"),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
Handler: c.Handler(r),
}
log.Fatal(srv.ListenAndServe())
}