Skip to content

Commit 437bdc3

Browse files
committed
cli/js console: if corsDomain is not given to startRpc, we fall back to value set on command line with -corsDomain
1 parent ae9efa5 commit 437bdc3

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

cmd/geth/admin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ func (js *jsre) startRPC(call otto.FunctionCall) otto.Value {
204204
fmt.Println(err)
205205
return otto.FalseValue()
206206
}
207+
207208
port, err := call.Argument(1).ToInteger()
208209
if err != nil {
209210
fmt.Println(err)
210211
return otto.FalseValue()
211212
}
212213

213-
var corsDomain string
214+
corsDomain := js.corsDomain
214215
if len(call.ArgumentList) > 2 {
215216
corsDomain, err = call.Argument(2).ToString()
216217
if err != nil {

cmd/geth/js.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,19 @@ func (r dumbterm) PasswordPrompt(p string) (string, error) {
5959
func (r dumbterm) AppendHistory(string) {}
6060

6161
type jsre struct {
62-
re *re.JSRE
63-
ethereum *eth.Ethereum
64-
xeth *xeth.XEth
65-
ps1 string
66-
atexit func()
67-
62+
re *re.JSRE
63+
ethereum *eth.Ethereum
64+
xeth *xeth.XEth
65+
ps1 string
66+
atexit func()
67+
corsDomain string
6868
prompter
6969
}
7070

71-
func newJSRE(ethereum *eth.Ethereum, libPath string, interactive bool) *jsre {
71+
func newJSRE(ethereum *eth.Ethereum, libPath string, interactive bool, corsDomain string) *jsre {
7272
js := &jsre{ethereum: ethereum, ps1: "> "}
73+
// set default cors domain used by startRpc from CLI flag
74+
js.corsDomain = corsDomain
7375
js.xeth = xeth.New(ethereum, js)
7476
js.re = re.New(libPath)
7577
js.apiBindings()

cmd/geth/js_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testJEthRE(t *testing.T) (repl *jsre, ethereum *eth.Ethereum, err error) {
4747
return
4848
}
4949
assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext")
50-
repl = newJSRE(ethereum, assetPath, false)
50+
repl = newJSRE(ethereum, assetPath, false, "")
5151
return
5252
}
5353

cmd/geth/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func console(ctx *cli.Context) {
296296
}
297297

298298
startEth(ctx, ethereum)
299-
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), true)
299+
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), true, ctx.GlobalString(utils.RPCCORSDomainFlag.Name))
300300
repl.interactive()
301301

302302
ethereum.Stop()
@@ -311,7 +311,7 @@ func execJSFiles(ctx *cli.Context) {
311311
}
312312

313313
startEth(ctx, ethereum)
314-
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), false)
314+
repl := newJSRE(ethereum, ctx.String(utils.JSpathFlag.Name), false, ctx.GlobalString(utils.RPCCORSDomainFlag.Name))
315315
for _, file := range ctx.Args() {
316316
repl.exec(file)
317317
}

0 commit comments

Comments
 (0)