fix api naming convention

This commit is contained in:
AJ ONeal 2017-05-20 04:51:44 +00:00
parent 3cf54f2b9a
commit da008ea658
1 changed files with 20 additions and 5 deletions

View File

@ -12,7 +12,11 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
xconfx.appApiGrantsPath = path.join(__dirname, '..', '..', 'packages', 'client-api-grants');
function notConfigured(req, res) {
res.send({ error: { message: "api package '" + req.pkgId + "' not configured for client uri '" + req.experienceId + "'" } });
var msg = "api package '" + req.pkgId + "' not configured for client uri '" + req.experienceId + "'"
+ ". To configure it place a new line '" + req.pkgId + "' in the file '/srv/walnut/packages/client-api-grants/" + req.experienceId + "'"
;
res.send({ error: { message: msg } });
}
/*
@ -23,12 +27,14 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
function isThisClientAllowedToUseThisPkg(myConf, clientUrih, pkgId) {
var appApiGrantsPath = path.join(myConf.appApiGrantsPath, clientUrih);
console.log('sanity exists?', appApiGrantsPath);;
console.log('sanity exists?', appApiGrantsPath);
return fs.readFileAsync(appApiGrantsPath, 'utf8').then(function (text) {
console.log('sanity', text);
return text.trim().split(/\n/);
}, function (rer) {
console.error(rer);
}, function (err) {
if ('ENOENT' !== err.code) {
console.error(err);
}
return [];
}).then(function (apis) {
if (apis.some(function (api) {
@ -128,8 +134,17 @@ console.error(rer);
return function (req, res, next) {
cors(req, res, function () {
console.log('[sanity check]', req.url);
// Canonical client names
// example.com should use api.example.com/api for all requests
// sub.example.com/api should resolve to sub.example.com
// example.com/subpath/api should resolve to example.com#subapp
// sub.example.com/subpath/api should resolve to sub.example.com#subapp
var clientUrih = req.hostname.replace(/^api\./, '') + req.url.replace(/\/api\/.*/, '/').replace(/\/+/g, '#').replace(/#$/, '');
var pkgId = req.url.replace(/.*\/api\//, '').replace(/^\//, '').replace(/\/$/, '');
// Canonical package names
// '/api/com.daplie.hello/hello' should resolve to 'com.daplie.hello'
// '/subapp/api/com.daplie.hello/hello' should also 'com.daplie.hello'
// '/subapp/api/com.daplie.hello/' may exist... must be a small api
var pkgId = req.url.replace(/.*\/api\//, '').replace(/^\//, '').replace(/\/.*/, '');
var now = Date.now();
var hasBeenHandled = false;