simplified adding new com.daplie.goldilocks apis
This commit is contained in:
parent
403ec90c2d
commit
aea4725fb0
36
lib/app.js
36
lib/app.js
|
@ -13,11 +13,11 @@ module.exports = function (myDeps, conf, overrideHttp) {
|
||||||
var serveIndexMap = {};
|
var serveIndexMap = {};
|
||||||
var content = conf.content;
|
var content = conf.content;
|
||||||
//var server;
|
//var server;
|
||||||
var serveInit;
|
var goldilocksApis;
|
||||||
var app;
|
var app;
|
||||||
var request;
|
var request;
|
||||||
|
|
||||||
function createServeInit() {
|
function createGoldilocksApis() {
|
||||||
var PromiseA = require('bluebird');
|
var PromiseA = require('bluebird');
|
||||||
var OAUTH3 = require('../packages/assets/org.oauth3');
|
var OAUTH3 = require('../packages/assets/org.oauth3');
|
||||||
require('../packages/assets/org.oauth3/oauth3.domains.js');
|
require('../packages/assets/org.oauth3/oauth3.domains.js');
|
||||||
|
@ -198,31 +198,19 @@ module.exports = function (myDeps, conf, overrideHttp) {
|
||||||
path.modules.forEach(mapMap);
|
path.modules.forEach(mapMap);
|
||||||
});
|
});
|
||||||
|
|
||||||
return app.use('/', function (req, res, next) {
|
return app.use('/api/com.daplie.goldilocks/:name', function (req, res, next) {
|
||||||
if (!req.headers.host) {
|
if (!goldilocksApis) {
|
||||||
next(new Error('missing HTTP Host header'));
|
goldilocksApis = createGoldilocksApis();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === req.url.indexOf('/api/com.daplie.goldilocks/')) {
|
if (typeof goldilocksApis[req.params.name] === 'function') {
|
||||||
if (!serveInit) {
|
goldilocksApis[req.params.name](req, res);
|
||||||
serveInit = createServeInit();
|
} else {
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
}
|
}).use('/', function (req, res, next) {
|
||||||
if ('/api/com.daplie.goldilocks/init' === req.url) {
|
if (!req.headers.host) {
|
||||||
serveInit.init(req, res);
|
next(new Error('missing HTTP Host header'));
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ('/api/com.daplie.goldilocks/tunnel' === req.url) {
|
|
||||||
serveInit.tunnel(req, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ('/api/com.daplie.goldilocks/config' === req.url) {
|
|
||||||
serveInit.config(req, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ('/api/com.daplie.goldilocks/request' === req.url) {
|
|
||||||
serveInit.request(req, res);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue