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 content = conf.content;
|
||||
//var server;
|
||||
var serveInit;
|
||||
var goldilocksApis;
|
||||
var app;
|
||||
var request;
|
||||
|
||||
function createServeInit() {
|
||||
function createGoldilocksApis() {
|
||||
var PromiseA = require('bluebird');
|
||||
var OAUTH3 = require('../packages/assets/org.oauth3');
|
||||
require('../packages/assets/org.oauth3/oauth3.domains.js');
|
||||
|
@ -198,31 +198,19 @@ module.exports = function (myDeps, conf, overrideHttp) {
|
|||
path.modules.forEach(mapMap);
|
||||
});
|
||||
|
||||
return app.use('/', function (req, res, next) {
|
||||
if (!req.headers.host) {
|
||||
next(new Error('missing HTTP Host header'));
|
||||
return;
|
||||
return app.use('/api/com.daplie.goldilocks/:name', function (req, res, next) {
|
||||
if (!goldilocksApis) {
|
||||
goldilocksApis = createGoldilocksApis();
|
||||
}
|
||||
|
||||
if (0 === req.url.indexOf('/api/com.daplie.goldilocks/')) {
|
||||
if (!serveInit) {
|
||||
serveInit = createServeInit();
|
||||
if (typeof goldilocksApis[req.params.name] === 'function') {
|
||||
goldilocksApis[req.params.name](req, res);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
if ('/api/com.daplie.goldilocks/init' === req.url) {
|
||||
serveInit.init(req, res);
|
||||
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);
|
||||
}).use('/', function (req, res, next) {
|
||||
if (!req.headers.host) {
|
||||
next(new Error('missing HTTP Host header'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue