|
|
@ -161,7 +161,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
|
|
|
|
function accountRequired(req, res, next) { |
|
|
|
// if this already has auth, great
|
|
|
|
if (req.oauth3.ppid) { |
|
|
|
if (req.oauth3.ppid && req.oauth3.accountIdx) { |
|
|
|
next(); |
|
|
|
return; |
|
|
|
} |
|
|
@ -305,7 +305,27 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
myApp.handleRejection = rejectableRequest; |
|
|
|
myApp.grantsRequired = grantsRequired; |
|
|
|
|
|
|
|
myApp.use('/', require('./oauth3').attachOauth3); |
|
|
|
function getSitePackageStoreProp(otherPkgId) { |
|
|
|
var restPath = path.join(myConf.restPath, otherPkgId); |
|
|
|
var apiPath = path.join(myConf.apiPath, otherPkgId); |
|
|
|
var dir; |
|
|
|
|
|
|
|
// TODO usage package.json as a falback if the standard location is not used
|
|
|
|
try { |
|
|
|
dir = require(path.join(apiPath, 'models.js')); |
|
|
|
} catch(e) { |
|
|
|
dir = require(path.join(restPath, 'models.js')); |
|
|
|
} |
|
|
|
|
|
|
|
return getSiteStore(clientUrih, otherPkgId, dir); |
|
|
|
} |
|
|
|
|
|
|
|
function attachOauth3(req, res, next) { |
|
|
|
return getSitePackageStoreProp('issuer@oauth3.org').then(function (Models) { |
|
|
|
return require('./oauth3').attachOauth3(Models, req, res, next); |
|
|
|
}); |
|
|
|
} |
|
|
|
myApp.use('/', attachOauth3); |
|
|
|
|
|
|
|
// TODO delete these caches when config changes
|
|
|
|
var _stripe; |
|
|
@ -318,7 +338,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
//if (xconfx.debug) { console.log('[api.js] loading handler prereqs'); }
|
|
|
|
return getSiteConfig(clientUrih).then(function (siteConfig) { |
|
|
|
//if (xconfx.debug) { console.log('[api.js] loaded handler site config'); }
|
|
|
|
Object.defineProperty(req, 'getSiteMailer', { |
|
|
|
|
|
|
|
// Use getSiteCapability('email@daplie.com') instead
|
|
|
|
Object.defineProperty(req, 'getSiteMailer' /*deprecated*/, { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
|
, writable: false |
|
|
@ -355,6 +377,13 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
Object.defineProperty(req, 'getSitePackageStore', { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
|
, writable: false |
|
|
|
, value: getSitePackageStoreProp |
|
|
|
}); |
|
|
|
|
|
|
|
Object.defineProperty(req, 'getSiteStore', { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
@ -820,14 +849,37 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
myApp.handleRejection = rejectableRequest; |
|
|
|
myApp.grantsRequired = grantsRequired; |
|
|
|
|
|
|
|
myApp.use('/', require('./oauth3').cookieOauth3); |
|
|
|
function otherGetSitePackageStoreProp(otherPkgId) { |
|
|
|
var restPath = path.join(myConf.restPath, otherPkgId); |
|
|
|
var apiPath = path.join(myConf.apiPath, otherPkgId); |
|
|
|
var dir; |
|
|
|
|
|
|
|
// TODO usage package.json as a falback if the standard location is not used
|
|
|
|
try { |
|
|
|
dir = require(path.join(apiPath, 'models.js')); |
|
|
|
} catch(e) { |
|
|
|
dir = require(path.join(restPath, 'models.js')); |
|
|
|
} |
|
|
|
|
|
|
|
return getSiteStore(clientUrih, otherPkgId, dir); |
|
|
|
} |
|
|
|
myApp.use('/', function cookieAttachOauth3(req, res, next) { |
|
|
|
return otherGetSitePackageStoreProp('issuer@oauth3.org').then(function (Models) { |
|
|
|
return require('./oauth3').cookieOauth3(Models, req, res, next); |
|
|
|
}); |
|
|
|
}); |
|
|
|
myApp.use('/', function (req, res, next) { |
|
|
|
console.log('########################################### session ###############################'); |
|
|
|
console.log('req.url', req.url); |
|
|
|
console.log('req.oauth3', req.oauth3); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
myApp.post('/assets/issuer@oauth3.org/session', require('./oauth3').attachOauth3, function (req, res) { |
|
|
|
function otherAttachOauth3(req, res, next) { |
|
|
|
return otherGetSitePackageStoreProp('issuer@oauth3.org').then(function (Models) { |
|
|
|
return require('./oauth3').attachOauth3(Models, req, res, next); |
|
|
|
}); |
|
|
|
} |
|
|
|
myApp.post('/assets/issuer@oauth3.org/session', otherAttachOauth3, function (req, res) { |
|
|
|
console.log('get the session'); |
|
|
|
console.log(req.url); |
|
|
|
console.log("req.cookies:"); |
|
|
@ -1004,7 +1056,8 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
// sub.example.com/api should resolve to sub.example.com
|
|
|
|
// example.com/subapp/api should resolve to example.com#subapp
|
|
|
|
// sub.example.com/subapp/api should resolve to sub.example.com#subapp
|
|
|
|
var clientUrih = req.hostname.replace(/^(api|assets)\./, '') + req.url.replace(/\/(api|assets)\/.*/, '/').replace(/\/+/g, '#').replace(/#$/, ''); |
|
|
|
var appUri = req.hostname.replace(/^(api|assets)\./, '') + req.url.replace(/\/(api|assets)\/.*/, '/').replace(/\/$/, ''); |
|
|
|
var clientUrih = appUri.replace(/\/+/g, '#').replace(/#$/, ''); |
|
|
|
var clientApiUri = req.hostname.replace(/^(api|assets)\./, 'api.') + req.url.replace(/\/(api|assets)\/.*/, '/').replace(/\/$/, ''); |
|
|
|
var clientAssetsUri = req.hostname.replace(/^(api|assets)\./, 'assets.') + req.url.replace(/\/(api|assets)\/.*/, '/').replace(/\/$/, ''); |
|
|
|
//var clientAssetsUri = req.hostname.replace(/^(api|assets)\./, 'api.') + req.url.replace(/\/(api|assets)\/.*/, '/').replace(/\/$/, '');
|
|
|
@ -1016,7 +1069,12 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
var now = Date.now(); |
|
|
|
var hasBeenHandled = false; |
|
|
|
|
|
|
|
// Existing (Deprecated)
|
|
|
|
Object.defineProperty(req, 'clientUrl', { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
|
, writable: false |
|
|
|
, value: (req.headers.referer || ('https://' + appUri)).replace(/\/$/, '').replace(/\?.*/, '') |
|
|
|
}); |
|
|
|
Object.defineProperty(req, 'apiUrlPrefix', { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
@ -1029,7 +1087,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
, writable: false |
|
|
|
, value: 'https://' + clientAssetsUri + '/assets/' + pkgId |
|
|
|
}); |
|
|
|
Object.defineProperty(req, 'experienceId', { |
|
|
|
Object.defineProperty(req, 'experienceId' /*deprecated*/, { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
|
, writable: false |
|
|
@ -1054,7 +1112,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { |
|
|
|
, value: pkgId |
|
|
|
}); |
|
|
|
|
|
|
|
// New
|
|
|
|
Object.defineProperty(req, 'clientUrih', { |
|
|
|
enumerable: true |
|
|
|
, configurable: false |
|
|
|