-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
46 lines (41 loc) · 1 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
package main
import (
"errors"
"fmt"
"net/http"
"os"
"github.com/rs/cors"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Printf("got / request from %s\n", r.RemoteAddr)
w.Header().Set("Content-Type", "application/json")
_, err := w.Write([]byte(greeting()))
if err != nil {
panic(err)
}
})
c := cors.New(cors.Options{
AllowedOrigins: []string{
"http://greetings.kylepenfound.com",
"https://dagger-demo.netlify.app",
"http://localhost:8081",
"http://localhost:1313",
},
// Enable Debugging for testing, consider disabling in production
Debug: true,
})
handler := c.Handler(mux)
err := http.ListenAndServe(":8080", handler)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("server closed\n")
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}
func greeting() string {
greeting := "Greetings Daggernauts!"
return fmt.Sprintf("{\"greeting\":\"%s\"}", greeting)
}