|
|
@ -44,6 +44,8 @@ func main() {
|
|
|
|
dbaddr := flag.String("dbaddr", "localhost", "database address")
|
|
|
|
dbaddr := flag.String("dbaddr", "localhost", "database address")
|
|
|
|
dbname := flag.String("dbname", "pokeroguedb", "database name")
|
|
|
|
dbname := flag.String("dbname", "pokeroguedb", "database name")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clienturl := flag.String("clienturl", "https://pokerogue.net", "client url")
|
|
|
|
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
|
|
// register gob types
|
|
|
|
// register gob types
|
|
|
@ -70,7 +72,7 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// start web server
|
|
|
|
// start web server
|
|
|
|
handler := prodHandler(mux)
|
|
|
|
handler := prodHandler(mux, clienturl)
|
|
|
|
if *debug {
|
|
|
|
if *debug {
|
|
|
|
handler = debugHandler(mux)
|
|
|
|
handler = debugHandler(mux)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -105,11 +107,11 @@ func createListener(proto, addr string) (net.Listener, error) {
|
|
|
|
return listener, nil
|
|
|
|
return listener, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func prodHandler(router *http.ServeMux) http.Handler {
|
|
|
|
func prodHandler(router *http.ServeMux, clienturl *string) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
|
|
|
|
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
|
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST")
|
|
|
|
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET, POST")
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", "https://pokerogue.net")
|
|
|
|
w.Header().Set("Access-Control-Allow-Origin", *clienturl)
|
|
|
|
|
|
|
|
|
|
|
|
if r.Method == "OPTIONS" {
|
|
|
|
if r.Method == "OPTIONS" {
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|