cli/js console: if corsDomain is not given to startRpc, we fall back to value set on command line with `-corsDomain`
This commit is contained in:
parent
1b7c017076
commit
6b1b5a4a2a
|
@ -203,13 +203,14 @@ func (js *jsre) startRPC(call otto.FunctionCall) otto.Value {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := call.Argument(1).ToInteger()
|
port, err := call.Argument(1).ToInteger()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
var corsDomain string
|
corsDomain := js.corsDomain
|
||||||
if len(call.ArgumentList) > 2 {
|
if len(call.ArgumentList) > 2 {
|
||||||
corsDomain, err = call.Argument(2).ToString()
|
corsDomain, err = call.Argument(2).ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -59,17 +59,19 @@ func (r dumbterm) PasswordPrompt(p string) (string, error) {
|
||||||
func (r dumbterm) AppendHistory(string) {}
|
func (r dumbterm) AppendHistory(string) {}
|
||||||
|
|
||||||
type jsre struct {
|
type jsre struct {
|
||||||
re *re.JSRE
|
re *re.JSRE
|
||||||
ethereum *eth.Ethereum
|
ethereum *eth.Ethereum
|
||||||
xeth *xeth.XEth
|
xeth *xeth.XEth
|
||||||
ps1 string
|
ps1 string
|
||||||
atexit func()
|
atexit func()
|
||||||
|
corsDomain string
|
||||||
prompter
|
prompter
|
||||||
}
|
}
|
||||||
|
|
||||||
func newJSRE(ethereum *eth.Ethereum, libPath string, interactive bool) *jsre {
|
func newJSRE(ethereum *eth.Ethereum, libPath string, interactive bool, corsDomain string) *jsre {
|
||||||
js := &jsre{ethereum: ethereum, ps1: "> "}
|
js := &jsre{ethereum: ethereum, ps1: "> "}
|
||||||
|
// set default cors domain used by startRpc from CLI flag
|
||||||
|
js.corsDomain = corsDomain
|
||||||
js.xeth = xeth.New(ethereum, js)
|
js.xeth = xeth.New(ethereum, js)
|
||||||
js.re = re.New(libPath)
|
js.re = re.New(libPath)
|
||||||
js.apiBindings()
|
js.apiBindings()
|
||||||
|
|
|
@ -36,7 +36,7 @@ func testJEthRE(t *testing.T) (*jsre, *eth.Ethereum) {
|
||||||
t.Fatal("%v", err)
|
t.Fatal("%v", err)
|
||||||
}
|
}
|
||||||
assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
|
assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
|
||||||
repl := newJSRE(ethereum, assetPath, false)
|
repl := newJSRE(ethereum, assetPath, false, "")
|
||||||
return repl, ethereum
|
return repl, ethereum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ func console(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
startEth(ctx, ethereum)
|
startEth(ctx, ethereum)
|
||||||
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), true)
|
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), true, ctx.GlobalString(utils.RPCCORSDomainFlag.Name))
|
||||||
repl.interactive()
|
repl.interactive()
|
||||||
|
|
||||||
ethereum.Stop()
|
ethereum.Stop()
|
||||||
|
@ -311,7 +311,7 @@ func execJSFiles(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
startEth(ctx, ethereum)
|
startEth(ctx, ethereum)
|
||||||
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), false)
|
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), false, ctx.GlobalString(utils.RPCCORSDomainFlag.Name))
|
||||||
for _, file := range ctx.Args() {
|
for _, file := range ctx.Args() {
|
||||||
repl.exec(file)
|
repl.exec(file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue