diff --git a/lib/admin/apis.js b/lib/admin/apis.js index 5bbe49a..e4ea68e 100644 --- a/lib/admin/apis.js +++ b/lib/admin/apis.js @@ -60,6 +60,13 @@ module.exports.create = function (deps, conf) { } function isAuthorized(req, res, fn) { + // OPTIONS requests are only to determine if a particular request is allowed, and the + // browser won't send the session header with this request, so don't try to authenticate. + if (req.method === 'OPTIONS') { + fn(); + return; + } + var auth = jwt.decode((req.headers.authorization||'').replace(/^bearer\s+/i, '')); if (!auth) { res.statusCode = 401; diff --git a/lib/admin/config.js b/lib/admin/config.js index 41f40a4..2d10423 100644 --- a/lib/admin/config.js +++ b/lib/admin/config.js @@ -50,9 +50,8 @@ var moduleSchemas = { } // the dns control modules for DDNS -, dns_oauth3_org: { - name: 'dns@oauth3.org' - , type: 'object' +, 'dns@oauth3.org': { + type: 'object' , required: [ 'token_id' ] , properties: { token_id: { type: 'string' } @@ -67,10 +66,6 @@ moduleSchemas.forward.properties.ports = { type: 'array', items: portSchema }; Object.keys(moduleSchemas).forEach(function (name) { var schema = moduleSchemas[name]; - if (schema.name) { - name = schema.name; - delete schema.name; - } schema.id = '/modules/'+name; schema.required = ['id', 'type'].concat(schema.required || []); schema.properties.id = { type: 'string' }; diff --git a/lib/ddns/index.js b/lib/ddns/index.js index 60878cf..df70ab9 100644 --- a/lib/ddns/index.js +++ b/lib/ddns/index.js @@ -265,8 +265,14 @@ module.exports.create = function (deps, conf) { }).filter(Boolean)); } - recheckPubAddr(); - setInterval(recheckPubAddr, 5*60*1000); + function check() { + recheckPubAddr().catch(function (err) { + console.error('failed to handle all actions needed for DDNS'); + console.error(err); + }); + } + check(); + setInterval(check, 5*60*1000); var curConf; function updateConf() { diff --git a/lib/modules/tls.js b/lib/modules/tls.js index 2b9a614..63d4d38 100644 --- a/lib/modules/tls.js +++ b/lib/modules/tls.js @@ -50,10 +50,7 @@ module.exports.create = function (deps, config, netHandler) { return; } - process.nextTick(function () { - socket.unshift(opts.firstChunk); - }); - + writer.write(opts.firstChunk); socket.pipe(writer); writer.pipe(socket); diff --git a/package-lock.json b/package-lock.json index 08e55c5..67f9108 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1907,9 +1907,9 @@ } }, "socket-pair": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/socket-pair/-/socket-pair-1.0.1.tgz", - "integrity": "sha1-mneFcEv9yOj2NxwodeyjIeMT/po=", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/socket-pair/-/socket-pair-1.0.3.tgz", + "integrity": "sha512-O1WJMNIPAAGCzzJi1Lk9K9adctKM4DukiUO6G6sQSs+CqEAZ5uGX86uIMDKygBZZr62YHDoOGH1rJShOzw6i9Q==", "requires": { "bluebird": "3.5.0" } diff --git a/package.json b/package.json index 9028745..20387c8 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "serve-static": "^1.10.0", "server-destroy": "^1.0.1", "sni": "^1.0.0", - "socket-pair": "^1.0.1", + "socket-pair": "^1.0.3", "socksv5": "0.0.6", "stunnel": "git+https://git.daplie.com/Daplie/node-tunnel-client.git#v1", "stunneld": "git+https://git.daplie.com/Daplie/node-tunnel-server.git#v1",