support text linked packages
This commit is contained in:
parent
69a18ad7d4
commit
064f4ca903
51
lib/apis.js
51
lib/apis.js
|
@ -108,7 +108,23 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
|
|
||||||
function loadRestHelper(myConf, clientUrih, pkgId) {
|
function loadRestHelper(myConf, clientUrih, pkgId) {
|
||||||
var pkgPath = path.join(myConf.restPath, pkgId);
|
var pkgPath = path.join(myConf.restPath, pkgId);
|
||||||
|
var pkgLinks = [];
|
||||||
|
pkgLinks.push(pkgId);
|
||||||
|
|
||||||
|
// TODO allow recursion, but catch cycles
|
||||||
|
return fs.lstatAsync(pkgPath).then(function (stat) {
|
||||||
|
if (!stat.isFile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.readFileAsync(pkgPath, 'utf8').then(function (text) {
|
||||||
|
pkgId = text.trim();
|
||||||
|
pkgPath = path.join(myConf.restPath, pkgId);
|
||||||
|
});
|
||||||
|
}, function () {
|
||||||
|
// ignore error
|
||||||
|
return;
|
||||||
|
}).then(function () {
|
||||||
// TODO should not require package.json. Should work with files alone.
|
// TODO should not require package.json. Should work with files alone.
|
||||||
return fs.readFileAsync(path.join(pkgPath, 'package.json'), 'utf8').then(function (text) {
|
return fs.readFileAsync(path.join(pkgPath, 'package.json'), 'utf8').then(function (text) {
|
||||||
var pkg = JSON.parse(text);
|
var pkg = JSON.parse(text);
|
||||||
|
@ -139,27 +155,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
console.log('DEBUG pkgPath', pkgPath);
|
console.log('DEBUG pkgPath', pkgPath);
|
||||||
myApp = express();
|
myApp = express();
|
||||||
|
|
||||||
/*
|
|
||||||
var pkgConf = {
|
|
||||||
pagespath: path.join(__dirname, '..', '..', 'packages', 'pages') + path.sep
|
|
||||||
, apipath: path.join(__dirname, '..', '..', 'packages', 'apis') + path.sep
|
|
||||||
, servicespath: path.join(__dirname, '..', '..', 'packages', 'services')
|
|
||||||
, vhostsMap: vhostsMap
|
|
||||||
, vhostPatterns: null
|
|
||||||
, server: webserver
|
|
||||||
, externalPort: info.conf.externalPort
|
|
||||||
, primaryNameserver: info.conf.primaryNameserver
|
|
||||||
, nameservers: info.conf.nameservers
|
|
||||||
, privkey: info.conf.privkey
|
|
||||||
, pubkey: info.conf.pubkey
|
|
||||||
, redirects: info.conf.redirects
|
|
||||||
, apiPrefix: '/api'
|
|
||||||
, 'org.oauth3.consumer': info.conf['org.oauth3.consumer']
|
|
||||||
, 'org.oauth3.provider': info.conf['org.oauth3.provider']
|
|
||||||
, keys: info.conf.keys
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
var _getOauth3Controllers = pkgDeps.getOauth3Controllers = require('oauthcommon/example-oauthmodels').create(
|
var _getOauth3Controllers = pkgDeps.getOauth3Controllers = require('oauthcommon/example-oauthmodels').create(
|
||||||
{ sqlite3Sock: xconfx.sqlite3Sock, ipcKey: xconfx.ipcKey }
|
{ sqlite3Sock: xconfx.sqlite3Sock, ipcKey: xconfx.ipcKey }
|
||||||
).getControllers;
|
).getControllers;
|
||||||
|
@ -173,14 +168,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
|
|
||||||
myApp.use('/', function preHandler(req, res, next) {
|
myApp.use('/', function preHandler(req, res, next) {
|
||||||
return getSiteConfig(clientUrih).then(function (siteConfig) {
|
return getSiteConfig(clientUrih).then(function (siteConfig) {
|
||||||
/*
|
|
||||||
Object.defineProperty(req, 'siteConfig', {
|
|
||||||
enumerable: true
|
|
||||||
, configurable: false
|
|
||||||
, writable: false
|
|
||||||
, value: siteConfig
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
Object.defineProperty(req, 'getSiteMailer', {
|
Object.defineProperty(req, 'getSiteMailer', {
|
||||||
enumerable: true
|
enumerable: true
|
||||||
, configurable: false
|
, configurable: false
|
||||||
|
@ -254,10 +241,14 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
localCache.pkgs[pkgId] = { pkg: pkg, handler: handler || myApp, createdAt: Date.now() };
|
localCache.pkgs[pkgId] = { pkgId: pkgId, pkg: pkg, handler: handler || myApp, createdAt: Date.now() };
|
||||||
|
pkgLinks.forEach(function (pkgLink) {
|
||||||
|
localCache.pkgs[pkgLink] = localCache.pkgs[pkgId];
|
||||||
|
});
|
||||||
return localCache.pkgs[pkgId];
|
return localCache.pkgs[pkgId];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read packages/apis/sub.sld.tld (forward dns) to find list of apis as tld.sld.sub (reverse dns)
|
// Read packages/apis/sub.sld.tld (forward dns) to find list of apis as tld.sld.sub (reverse dns)
|
||||||
|
|
Loading…
Reference in New Issue