3

我正在尝试在成功服务的 aws linux 实例上运行 express-stormpath。我已经检查了我的密钥和应用程序的两倍和三倍,并确保它们已连接到应用程序。我去了一个新的虚拟机并使用最简单的服务来确保我成功地为sailsjs应用程序提供服务的虚拟机中没有问题。

var express = require('express');
var stormpath = require('express-stormpath');

var app = express();

var stormpathInit = function(req,res,next) {
    stormpath.init(app, {
        apiKey: {
            id:'##########',
            secret: '############',
        },
        secretKey: 'theLongRoadToNowhere',
        application: 'https://api.stormpath.com/v1/applications/###',
        website: true,
        api: true
    });
    next();
};

app.use(stormpathInit);

app.get('/', function (req, res) {
    res.send('<a href="/login">Login</a>');
});

/* and this failed as well with the same output only on server startup

app.use(stormpath.init(app, {
    apiKey: {
        id:'4SL89BZ47ALZX6T9W7S4NPUXS',
        secret: 's0dA33RPTAqcDAcdbwj6q9i0qDDEr0XyHhsBmjF34SY',
    },
    secretKey: 'theLongRoadToFreedomWillPayDividends',
    application: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ',
    website: true,
    api: true
}));
*/

app.listen(1337);

///////////////////////
The error output:

req.uri = undefined
/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/RequestExecutor.js:70
      throw new Error('request.uri field is required.');
            ^
Error: request.uri field is required.
    at RequestExecutor.executeRequest [as execute] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/RequestExecutor.js:70:13)
    at doRequest (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:277:27)
    at onCacheResult (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:301:5)
    at Array.<anonymous> (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/Cache.js:54:14)
    at DisabledCache.get.DisabledCache.set.DisabledCache.delete.DisabledCache.clear.DisabledCache.size (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/DisabledCache.js:11:62)
    at Cache.get (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/Cache.js:52:14)
    at CacheHandler.getCachedResource [as get] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/cache/CacheHandler.js:91:51)
    at Object.executeRequest [as exec] (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:294:22)
    at DataStore.getResource (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/ds/DataStore.js:122:16)
    at Client.getResource (/var/www/stormpath/node_modules/express-stormpath/node_modules/stormpath/lib/Client.js:313:38)

任何指导表示赞赏...

4

2 回答 2

3

不幸的是,photon 的答案对我不起作用,但在与 Stormpath 支持人员沟通后(这非常有帮助),以下解决了我的问题:

通过在 shell 中运行它来设置环境变量STORMPATH_APPLICATION_HREF

export STORMPATH_APPLICATION_HREF=<YourAppsHREF>

希望这也适用于其他人。

问题似乎是stormpath文档中的一个小错字。他们目前指示您设置一个名为STORMPATH_CLIENT_APPLICATION_HREF. 这是不正确的,应该STORMPATH_APPLICATION_HREF如上图。

于 2015-09-09T01:09:53.773 回答
2

我遇到了同样的问题,在查看了 Stormpath 中间件的当前默认选项后,更改以下行解决了我的问题。

application: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ'

application: {
    href: 'https://api.stormpath.com/v1/applications/1wShCspJ1NFnT1N1UM1laJ'
}
于 2015-09-08T09:34:11.707 回答