node/wallet: add cors option. see #397.

This commit is contained in:
Christopher Jeffrey 2018-03-29 22:22:47 -07:00
parent 6c8cf8c56a
commit c7d844ea37
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 22 additions and 4 deletions

View File

@ -143,7 +143,8 @@ class FullNode extends Node {
host: this.config.str('http-host'),
port: this.config.uint('http-port'),
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();

View File

@ -80,7 +80,8 @@ class HTTP extends Server {
*/
initRouter() {
this.use(this.cors());
if (this.options.cors)
this.use(this.cors());
if (!this.options.noAuth) {
this.use(this.basicAuth({
@ -679,6 +680,7 @@ class HTTPOptions {
this.apiKey = base58.encode(random.randomBytes(20));
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
this.noAuth = false;
this.cors = false;
this.prefix = null;
this.host = '127.0.0.1';
@ -727,6 +729,11 @@ class HTTPOptions {
this.noAuth = options.noAuth;
}
if (options.cors != null) {
assert(typeof options.cors === 'boolean');
this.cors = options.cors;
}
if (options.prefix != null) {
assert(typeof options.prefix === 'string');
this.prefix = options.prefix;

View File

@ -91,7 +91,8 @@ class SPVNode extends Node {
host: this.config.str('http-host'),
port: this.config.uint('http-port'),
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;

View File

@ -78,7 +78,8 @@ class HTTP extends Server {
*/
initRouter() {
this.use(this.cors());
if (this.options.cors)
this.use(this.cors());
if (!this.options.noAuth) {
this.use(this.basicAuth({
@ -1041,6 +1042,7 @@ class HTTPOptions {
this.adminToken = random.randomBytes(32);
this.serviceHash = this.apiHash;
this.noAuth = false;
this.cors = false;
this.walletAuth = false;
this.prefix = null;
@ -1106,6 +1108,11 @@ class HTTPOptions {
this.noAuth = options.noAuth;
}
if (options.cors != null) {
assert(typeof options.cors === 'boolean');
this.cors = options.cors;
}
if (options.walletAuth != null) {
assert(typeof options.walletAuth === 'boolean');
this.walletAuth = options.walletAuth;

View File

@ -69,6 +69,7 @@ class WalletNode extends Node {
apiKey: this.config.str('api-key'),
walletAuth: this.config.bool('wallet-auth'),
noAuth: this.config.bool('no-auth'),
cors: this.config.bool('cors'),
adminToken: this.config.str('admin-token')
});

View File

@ -70,6 +70,7 @@ class Plugin extends EventEmitter {
apiKey: this.config.str('api-key', node.config.str('api-key')),
walletAuth: this.config.bool('wallet-auth'),
noAuth: this.config.bool('no-auth'),
cors: this.config.bool('cors'),
adminToken: this.config.str('admin-token')
});