Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions code/go/0chain.net/blobber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"log"
"net"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
"strings"
"time"

"0chain.net/blobbercore/allocation"
Expand Down Expand Up @@ -193,25 +191,27 @@ func processMinioConfig(reader io.Reader) error {
return nil
}

func isValidOrigin(origin string) bool {
var url, err = url.Parse(origin)
if err != nil {
return false
}
var host = url.Hostname()
if host == "localhost" {
return true
}
if host == "0chain.net" || host == "0box.io" ||
strings.HasSuffix(host, ".0chain.net") ||
strings.HasSuffix(host, ".alphanet-0chain.net") ||
strings.HasSuffix(host, ".testnet-0chain.net") ||
strings.HasSuffix(host, ".devnet-0chain.net") ||
strings.HasSuffix(host, ".mainnet-0chain.net") {
return true
}
return false
}
// // Comment out to pass lint. Still keep this function around in case we want to
// // change how CORS validates origins.
// func isValidOrigin(origin string) bool {
// var url, err = url.Parse(origin)
// if err != nil {
// return false
// }
// var host = url.Hostname()
// if host == "localhost" {
// return true
// }
// if host == "0chain.net" || host == "0box.io" ||
// strings.HasSuffix(host, ".0chain.net") ||
// strings.HasSuffix(host, ".alphanet-0chain.net") ||
// strings.HasSuffix(host, ".testnet-0chain.net") ||
// strings.HasSuffix(host, ".devnet-0chain.net") ||
// strings.HasSuffix(host, ".mainnet-0chain.net") {
// return true
// }
// return false
// }

func main() {
deploymentMode := flag.Int("deployment_mode", 2, "deployment_mode")
Expand Down Expand Up @@ -335,7 +335,11 @@ func main() {
"X-Requested-With", "X-App-Client-ID",
"X-App-Client-Key", "Content-Type",
})
originsOk := handlers.AllowedOriginValidator(isValidOrigin)

// Allow anybody to access API.
// originsOk := handlers.AllowedOriginValidator(isValidOrigin)
originsOk := handlers.AllowedOrigins([]string{"*"})

methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT",
"DELETE", "OPTIONS"})

Expand Down