kopia lustrzana https://github.com/bugout-dev/moonstream
Merge pull request #300 from bugout-dev/cors-for-status-servers
CORS settings for status serverspull/302/head
commit
8e2809a978
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Ładowanie…
Reference in New Issue