Merge pull request #300 from bugout-dev/cors-for-status-servers

CORS settings for status servers
pull/302/head
Sergei Sumarokov 2021-10-01 16:31:10 +03:00 zatwierdzone przez GitHub
commit 8e2809a978
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -13,6 +13,7 @@ import (
)
var MOONSTREAM_IPC_PATH = os.Getenv("MOONSTREAM_IPC_PATH")
var MOONSTREAM_CORS_ALLOWED_ORIGINS = os.Getenv("MOONSTREAM_CORS_ALLOWED_ORIGINS")
type GethResponse struct {
Result string `json:"result"`
@ -26,8 +27,17 @@ type PingResponse struct {
Status string `json:"status"`
}
func setupCorsResponse(w *http.ResponseWriter, req *http.Request) {
(*w).Header().Set("Access-Control-Allow-Origin", MOONSTREAM_CORS_ALLOWED_ORIGINS)
(*w).Header().Set("Access-Control-Allow-Methods", "GET")
}
func ping(w http.ResponseWriter, req *http.Request) {
setupCorsResponse(&w, req)
log.Printf("%s, %s, %q", req.RemoteAddr, req.Method, req.URL.String())
if (*req).Method == "OPTIONS" {
return
}
w.Header().Set("Content-Type", "application/json")
response := PingResponse{Status: "ok"}
@ -35,7 +45,11 @@ func ping(w http.ResponseWriter, req *http.Request) {
}
func pingGeth(w http.ResponseWriter, req *http.Request) {
setupCorsResponse(&w, req)
log.Printf("%s, %s, %q", req.RemoteAddr, req.Method, req.URL.String())
if (*req).Method == "OPTIONS" {
return
}
postBody, err := json.Marshal(map[string]interface{}{
"jsonrpc": "2.0",

Wyświetl plik

@ -1,2 +1,3 @@
export MOONSTREAM_CRAWLERS_SERVER_PORT="8080"
export MOONSTREAM_IPC_PATH=null
export MOONSTREAM_CORS_ALLOWED_ORIGINS="http://localhost:3000,https://moonstream.to,https://www.moonstream.to,https://alpha.moonstream.to"

Wyświetl plik

@ -12,6 +12,7 @@ import (
)
var MOONSTREAM_DB_URI = os.Getenv("MOONSTREAM_DB_URI")
var MOONSTREAM_CORS_ALLOWED_ORIGINS = os.Getenv("MOONSTREAM_CORS_ALLOWED_ORIGINS")
type PingResponse struct {
Status string `json:"status"`
@ -21,8 +22,17 @@ type BlockResponse struct {
BlockNumber uint64 `json:"block_number"`
}
func setupCorsResponse(w *http.ResponseWriter, req *http.Request) {
(*w).Header().Set("Access-Control-Allow-Origin", MOONSTREAM_CORS_ALLOWED_ORIGINS)
(*w).Header().Set("Access-Control-Allow-Methods", "GET")
}
func ping(w http.ResponseWriter, req *http.Request) {
setupCorsResponse(&w, req)
log.Printf("%s, %s, %q", req.RemoteAddr, req.Method, req.URL.String())
if (*req).Method == "OPTIONS" {
return
}
w.Header().Set("Content-Type", "application/json")
response := PingResponse{Status: "ok"}
@ -30,7 +40,11 @@ func ping(w http.ResponseWriter, req *http.Request) {
}
func blockLatest(w http.ResponseWriter, req *http.Request) {
setupCorsResponse(&w, req)
log.Printf("%s, %s, %q", req.RemoteAddr, req.Method, req.URL.String())
if (*req).Method == "OPTIONS" {
return
}
w.Header().Set("Content-Type", "application/json")

Wyświetl plik

@ -1,2 +1,3 @@
export MOONSTREAM_DB_SERVER_PORT="8080"
export MOONSTREAM_DB_URI="postgresql://<username>:<password>@<db_host>:<db_port>/<db_name>"
export MOONSTREAM_CORS_ALLOWED_ORIGINS="http://localhost:3000,https://moonstream.to,https://www.moonstream.to,https://alpha.moonstream.to"