node/wallet: add cors option. see #397.
This commit is contained in:
parent
6c8cf8c56a
commit
c7d844ea37
@ -143,7 +143,8 @@ class FullNode extends Node {
|
|||||||
host: this.config.str('http-host'),
|
host: this.config.str('http-host'),
|
||||||
port: this.config.uint('http-port'),
|
port: this.config.uint('http-port'),
|
||||||
apiKey: this.config.str('api-key'),
|
apiKey: this.config.str('api-key'),
|
||||||
noAuth: this.config.bool('no-auth')
|
noAuth: this.config.bool('no-auth'),
|
||||||
|
cors: this.config.bool('cors')
|
||||||
});
|
});
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
|
|||||||
@ -80,7 +80,8 @@ class HTTP extends Server {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
initRouter() {
|
initRouter() {
|
||||||
this.use(this.cors());
|
if (this.options.cors)
|
||||||
|
this.use(this.cors());
|
||||||
|
|
||||||
if (!this.options.noAuth) {
|
if (!this.options.noAuth) {
|
||||||
this.use(this.basicAuth({
|
this.use(this.basicAuth({
|
||||||
@ -679,6 +680,7 @@ class HTTPOptions {
|
|||||||
this.apiKey = base58.encode(random.randomBytes(20));
|
this.apiKey = base58.encode(random.randomBytes(20));
|
||||||
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
||||||
this.noAuth = false;
|
this.noAuth = false;
|
||||||
|
this.cors = false;
|
||||||
|
|
||||||
this.prefix = null;
|
this.prefix = null;
|
||||||
this.host = '127.0.0.1';
|
this.host = '127.0.0.1';
|
||||||
@ -727,6 +729,11 @@ class HTTPOptions {
|
|||||||
this.noAuth = options.noAuth;
|
this.noAuth = options.noAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.cors != null) {
|
||||||
|
assert(typeof options.cors === 'boolean');
|
||||||
|
this.cors = options.cors;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.prefix != null) {
|
if (options.prefix != null) {
|
||||||
assert(typeof options.prefix === 'string');
|
assert(typeof options.prefix === 'string');
|
||||||
this.prefix = options.prefix;
|
this.prefix = options.prefix;
|
||||||
|
|||||||
@ -91,7 +91,8 @@ class SPVNode extends Node {
|
|||||||
host: this.config.str('http-host'),
|
host: this.config.str('http-host'),
|
||||||
port: this.config.uint('http-port'),
|
port: this.config.uint('http-port'),
|
||||||
apiKey: this.config.str('api-key'),
|
apiKey: this.config.str('api-key'),
|
||||||
noAuth: this.config.bool('no-auth')
|
noAuth: this.config.bool('no-auth'),
|
||||||
|
cors: this.config.bool('cors')
|
||||||
});
|
});
|
||||||
|
|
||||||
this.rescanJob = null;
|
this.rescanJob = null;
|
||||||
|
|||||||
@ -78,7 +78,8 @@ class HTTP extends Server {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
initRouter() {
|
initRouter() {
|
||||||
this.use(this.cors());
|
if (this.options.cors)
|
||||||
|
this.use(this.cors());
|
||||||
|
|
||||||
if (!this.options.noAuth) {
|
if (!this.options.noAuth) {
|
||||||
this.use(this.basicAuth({
|
this.use(this.basicAuth({
|
||||||
@ -1041,6 +1042,7 @@ class HTTPOptions {
|
|||||||
this.adminToken = random.randomBytes(32);
|
this.adminToken = random.randomBytes(32);
|
||||||
this.serviceHash = this.apiHash;
|
this.serviceHash = this.apiHash;
|
||||||
this.noAuth = false;
|
this.noAuth = false;
|
||||||
|
this.cors = false;
|
||||||
this.walletAuth = false;
|
this.walletAuth = false;
|
||||||
|
|
||||||
this.prefix = null;
|
this.prefix = null;
|
||||||
@ -1106,6 +1108,11 @@ class HTTPOptions {
|
|||||||
this.noAuth = options.noAuth;
|
this.noAuth = options.noAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.cors != null) {
|
||||||
|
assert(typeof options.cors === 'boolean');
|
||||||
|
this.cors = options.cors;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.walletAuth != null) {
|
if (options.walletAuth != null) {
|
||||||
assert(typeof options.walletAuth === 'boolean');
|
assert(typeof options.walletAuth === 'boolean');
|
||||||
this.walletAuth = options.walletAuth;
|
this.walletAuth = options.walletAuth;
|
||||||
|
|||||||
@ -69,6 +69,7 @@ class WalletNode extends Node {
|
|||||||
apiKey: this.config.str('api-key'),
|
apiKey: this.config.str('api-key'),
|
||||||
walletAuth: this.config.bool('wallet-auth'),
|
walletAuth: this.config.bool('wallet-auth'),
|
||||||
noAuth: this.config.bool('no-auth'),
|
noAuth: this.config.bool('no-auth'),
|
||||||
|
cors: this.config.bool('cors'),
|
||||||
adminToken: this.config.str('admin-token')
|
adminToken: this.config.str('admin-token')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -70,6 +70,7 @@ class Plugin extends EventEmitter {
|
|||||||
apiKey: this.config.str('api-key', node.config.str('api-key')),
|
apiKey: this.config.str('api-key', node.config.str('api-key')),
|
||||||
walletAuth: this.config.bool('wallet-auth'),
|
walletAuth: this.config.bool('wallet-auth'),
|
||||||
noAuth: this.config.bool('no-auth'),
|
noAuth: this.config.bool('no-auth'),
|
||||||
|
cors: this.config.bool('cors'),
|
||||||
adminToken: this.config.str('admin-token')
|
adminToken: this.config.str('admin-token')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user