load sites separately from packages
This commit is contained in:
parent
032ebe0302
commit
3cf54f2b9a
|
@ -218,7 +218,7 @@ install_my_app()
|
||||||
ln -sf ../node_modules /srv/walnut/core/node_modules
|
ln -sf ../node_modules /srv/walnut/core/node_modules
|
||||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer
|
sudo mkdir -p /srv/walnut/etc/org.oauth3.consumer
|
||||||
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
sudo mkdir -p /srv/walnut/etc/org.oauth3.provider
|
||||||
sudo mkdir -p /srv/walnut/packages/{client-api-grants,rest,api,pages,services}
|
sudo mkdir -p /srv/walnut/packages/{client-api-grants,rest,api,pages,services,sites}
|
||||||
#sudo chown -R $(whoami):$(whoami) /srv/walnut
|
#sudo chown -R $(whoami):$(whoami) /srv/walnut
|
||||||
sudo chown -R www-data:www-data /srv/walnut
|
sudo chown -R www-data:www-data /srv/walnut
|
||||||
sudo chmod -R ug+Xrw /srv/walnut
|
sudo chmod -R ug+Xrw /srv/walnut
|
||||||
|
|
21
lib/main.js
21
lib/main.js
|
@ -25,7 +25,7 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps, errorIfApi
|
||||||
|
|
||||||
res.statusCode = 302;
|
res.statusCode = 302;
|
||||||
res.setHeader('Location', url);
|
res.setHeader('Location', url);
|
||||||
res.end();
|
res.end("The static pages for '" + reason + "' are not listed in '" + path.join(xconfx.sitespath, reason) + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function disallowSymLinks(req, res) {
|
function disallowSymLinks(req, res) {
|
||||||
|
@ -67,19 +67,19 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps, errorIfApi
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadHandler(name) {
|
function loadSiteHandler(name) {
|
||||||
return function handler(req, res, next) {
|
return function handler(req, res, next) {
|
||||||
// path.join('packages/pages', 'com.daplie.hello') // package name (used as file-link)
|
// path.join('packages/pages', 'com.daplie.hello') // package name (used as file-link)
|
||||||
// path.join('packages/pages', 'domain.tld#hello') // dynamic exact url match
|
// path.join('packages/pages', 'domain.tld#hello') // dynamic exact url match
|
||||||
var packagepath = path.join(xconfx.staticpath, name);
|
var sitepath = path.join(xconfx.sitespath, name);
|
||||||
|
|
||||||
return fs.lstatAsync(packagepath).then(function (stat) {
|
return fs.lstatAsync(sitepath).then(function (stat) {
|
||||||
if (stat.isSymbolicLink()) {
|
if (stat.isSymbolicLink()) {
|
||||||
return disallowSymLinks;
|
return disallowSymLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
return express.static(packagepath);
|
return express.static(sitepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stat.isFile()) {
|
if (!stat.isFile()) {
|
||||||
|
@ -96,13 +96,13 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps, errorIfApi
|
||||||
// and if no file matches that 'tld.domain.app' may be tried next, and so on
|
// and if no file matches that 'tld.domain.app' may be tried next, and so on
|
||||||
//
|
//
|
||||||
// this may well become a .htaccess type of situation allowing for redirects and such
|
// this may well become a .htaccess type of situation allowing for redirects and such
|
||||||
return fs.readFileAsync(packagepath, 'utf8').then(function (text) {
|
return fs.readFileAsync(sitepath, 'utf8').then(function (text) {
|
||||||
// TODO allow cascading multiple lines
|
// TODO allow cascading multiple lines
|
||||||
text = text.trim().split(/\n/)[0];
|
text = text.trim().split(/\n/)[0];
|
||||||
|
|
||||||
// TODO rerun the above, disallowing link-style (or count or memoize to prevent infinite loop)
|
// TODO rerun the above, disallowing link-style (or count or memoize to prevent infinite loop)
|
||||||
// TODO make safe
|
// TODO make safe
|
||||||
packagepath = path.resolve(xconfx.staticpath, text);
|
var packagepath = path.resolve(xconfx.staticpath, text);
|
||||||
if (0 !== packagepath.indexOf(xconfx.staticpath)) {
|
if (0 !== packagepath.indexOf(xconfx.staticpath)) {
|
||||||
return securityError;
|
return securityError;
|
||||||
}
|
}
|
||||||
|
@ -127,9 +127,10 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps, errorIfApi
|
||||||
// TODO inter-process cache expirey
|
// TODO inter-process cache expirey
|
||||||
// TODO add to xconfx.staticpath
|
// TODO add to xconfx.staticpath
|
||||||
xconfx.staticpath = path.join(__dirname, '..', '..', 'packages', 'pages');
|
xconfx.staticpath = path.join(__dirname, '..', '..', 'packages', 'pages');
|
||||||
|
xconfx.sitespath = path.join(__dirname, '..', '..', 'packages', 'sites');
|
||||||
|
|
||||||
// Reads in each of the static apps as 'nodes'
|
// Reads in each of the sites directives as 'nodes'
|
||||||
return fs.readdirAsync(xconfx.staticpath).then(function (nodes) {
|
return fs.readdirAsync(xconfx.sitespath).then(function (nodes) {
|
||||||
if (opts && opts.clear) {
|
if (opts && opts.clear) {
|
||||||
localCache.statics = {};
|
localCache.statics = {};
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,7 @@ module.exports.create = function (app, xconfx, apiFactories, apiDeps, errorIfApi
|
||||||
console.log('[all apps]', name);
|
console.log('[all apps]', name);
|
||||||
if (!localCache.statics[name]) {
|
if (!localCache.statics[name]) {
|
||||||
console.log('[load this app]', name);
|
console.log('[load this app]', name);
|
||||||
localCache.statics[name] = { handler: loadHandler(name), createdAt: Date.now() };
|
localCache.statics[name] = { handler: loadSiteHandler(name), createdAt: Date.now() };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue