fix some misc problem found using browser to access API

This commit is contained in:
tigerbot 2017-10-25 11:00:06 -06:00
parent 00de23ded7
commit 72ff65e833
6 changed files with 22 additions and 17 deletions

View File

@ -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;

View File

@ -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' };

View File

@ -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() {

View File

@ -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);

6
package-lock.json generated
View File

@ -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"
}

View File

@ -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",