fix api naming convention
This commit is contained in:
parent
3cf54f2b9a
commit
da008ea658
25
lib/apis.js
25
lib/apis.js
|
@ -12,7 +12,11 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
xconfx.appApiGrantsPath = path.join(__dirname, '..', '..', 'packages', 'client-api-grants');
|
xconfx.appApiGrantsPath = path.join(__dirname, '..', '..', 'packages', 'client-api-grants');
|
||||||
|
|
||||||
function notConfigured(req, res) {
|
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) {
|
function isThisClientAllowedToUseThisPkg(myConf, clientUrih, pkgId) {
|
||||||
var appApiGrantsPath = path.join(myConf.appApiGrantsPath, clientUrih);
|
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) {
|
return fs.readFileAsync(appApiGrantsPath, 'utf8').then(function (text) {
|
||||||
console.log('sanity', text);
|
console.log('sanity', text);
|
||||||
return text.trim().split(/\n/);
|
return text.trim().split(/\n/);
|
||||||
}, function (rer) {
|
}, function (err) {
|
||||||
console.error(rer);
|
if ('ENOENT' !== err.code) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
return [];
|
return [];
|
||||||
}).then(function (apis) {
|
}).then(function (apis) {
|
||||||
if (apis.some(function (api) {
|
if (apis.some(function (api) {
|
||||||
|
@ -128,8 +134,17 @@ console.error(rer);
|
||||||
return function (req, res, next) {
|
return function (req, res, next) {
|
||||||
cors(req, res, function () {
|
cors(req, res, function () {
|
||||||
console.log('[sanity check]', req.url);
|
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 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 now = Date.now();
|
||||||
var hasBeenHandled = false;
|
var hasBeenHandled = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue