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) { 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, '')); var auth = jwt.decode((req.headers.authorization||'').replace(/^bearer\s+/i, ''));
if (!auth) { if (!auth) {
res.statusCode = 401; res.statusCode = 401;

View File

@ -50,9 +50,8 @@ var moduleSchemas = {
} }
// the dns control modules for DDNS // the dns control modules for DDNS
, dns_oauth3_org: { , 'dns@oauth3.org': {
name: 'dns@oauth3.org' type: 'object'
, type: 'object'
, required: [ 'token_id' ] , required: [ 'token_id' ]
, properties: { , properties: {
token_id: { type: 'string' } token_id: { type: 'string' }
@ -67,10 +66,6 @@ moduleSchemas.forward.properties.ports = { type: 'array', items: portSchema };
Object.keys(moduleSchemas).forEach(function (name) { Object.keys(moduleSchemas).forEach(function (name) {
var schema = moduleSchemas[name]; var schema = moduleSchemas[name];
if (schema.name) {
name = schema.name;
delete schema.name;
}
schema.id = '/modules/'+name; schema.id = '/modules/'+name;
schema.required = ['id', 'type'].concat(schema.required || []); schema.required = ['id', 'type'].concat(schema.required || []);
schema.properties.id = { type: 'string' }; schema.properties.id = { type: 'string' };

View File

@ -265,8 +265,14 @@ module.exports.create = function (deps, conf) {
}).filter(Boolean)); }).filter(Boolean));
} }
recheckPubAddr(); function check() {
setInterval(recheckPubAddr, 5*60*1000); 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; var curConf;
function updateConf() { function updateConf() {

View File

@ -50,10 +50,7 @@ module.exports.create = function (deps, config, netHandler) {
return; return;
} }
process.nextTick(function () { writer.write(opts.firstChunk);
socket.unshift(opts.firstChunk);
});
socket.pipe(writer); socket.pipe(writer);
writer.pipe(socket); writer.pipe(socket);

6
package-lock.json generated
View File

@ -1907,9 +1907,9 @@
} }
}, },
"socket-pair": { "socket-pair": {
"version": "1.0.1", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/socket-pair/-/socket-pair-1.0.1.tgz", "resolved": "https://registry.npmjs.org/socket-pair/-/socket-pair-1.0.3.tgz",
"integrity": "sha1-mneFcEv9yOj2NxwodeyjIeMT/po=", "integrity": "sha512-O1WJMNIPAAGCzzJi1Lk9K9adctKM4DukiUO6G6sQSs+CqEAZ5uGX86uIMDKygBZZr62YHDoOGH1rJShOzw6i9Q==",
"requires": { "requires": {
"bluebird": "3.5.0" "bluebird": "3.5.0"
} }

View File

@ -66,7 +66,7 @@
"serve-static": "^1.10.0", "serve-static": "^1.10.0",
"server-destroy": "^1.0.1", "server-destroy": "^1.0.1",
"sni": "^1.0.0", "sni": "^1.0.0",
"socket-pair": "^1.0.1", "socket-pair": "^1.0.3",
"socksv5": "0.0.6", "socksv5": "0.0.6",
"stunnel": "git+https://git.daplie.com/Daplie/node-tunnel-client.git#v1", "stunnel": "git+https://git.daplie.com/Daplie/node-tunnel-client.git#v1",
"stunneld": "git+https://git.daplie.com/Daplie/node-tunnel-server.git#v1", "stunneld": "git+https://git.daplie.com/Daplie/node-tunnel-server.git#v1",