-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (38 loc) · 1.19 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
package main
import (
"DSBackend/controllers"
"DSBackend/data"
"fmt"
"log"
"net/http"
"os"
"github.com/go-chi/chi"
"github.com/go-chi/cors"
_ "github.com/lib/pq"
)
func main() {
router := *chi.NewRouter()
c := cors.New(cors.Options{
//AllowedOrigins: []string{"https://duckstack.com"}, // Use this to allow specific origin hosts
AllowedOrigins: []string{"*"},
// AllowOriginFunc: func(r *http.Request, origin string) bool { return true },
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
//AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token", "X-Requested-With", "Access-Control-Allow-Headers"},
AllowedHeaders: []string{"*"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300, // Maximum value not ignored by any of major browsers
})
router.Use(c.Handler)
router.Get("/api/ui/update/{Screen}", controllers.UIEndpoint)
router.Post("/api/do/{Action}", controllers.DoEndpoint)
http.Handle("/", &router)
port := os.Getenv("PORT")
if (port == ""){
port = "8081"
}
data.InitBucket("duckstackui")
//REST
fmt.Println("DSBackend")
log.Fatal(http.ListenAndServe(":"+port, &router))
}