support text linked packages

This commit is contained in:
AJ ONeal 2017-05-26 23:09:49 +00:00
parent 69a18ad7d4
commit 064f4ca903
1 changed files with 121 additions and 130 deletions

View File

@ -108,7 +108,23 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
function loadRestHelper(myConf, clientUrih, 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.
return fs.readFileAsync(path.join(pkgPath, 'package.json'), 'utf8').then(function (text) {
var pkg = JSON.parse(text);
@ -139,27 +155,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
console.log('DEBUG pkgPath', pkgPath);
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(
{ sqlite3Sock: xconfx.sqlite3Sock, ipcKey: xconfx.ipcKey }
).getControllers;
@ -173,14 +168,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
myApp.use('/', function preHandler(req, res, next) {
return getSiteConfig(clientUrih).then(function (siteConfig) {
/*
Object.defineProperty(req, 'siteConfig', {
enumerable: true
, configurable: false
, writable: false
, value: siteConfig
});
*/
Object.defineProperty(req, 'getSiteMailer', {
enumerable: true
, configurable: false
@ -254,10 +241,14 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
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];
});
});
});
}
// Read packages/apis/sub.sld.tld (forward dns) to find list of apis as tld.sld.sub (reverse dns)