Tag: strongloop

MongoDB节点API上的ISODate和时区

我使用Node构build了一个API,IBM Strongloop框架以及一个MongoDB数据库。 我有一个date时区的问题。 在前端,我有一个反应datepicker创builddate对象。 我在法国,所以GMT + 1 。 如果我在2000年1月6日的前台创build了一个出生date ,XHR请求会发送“2000-01-05T23:00:00.000Z”给API。 如果我在前台尝试新date('2000-01-05T23:00:00.000Z'),我会得到正确的dateThu Jan 06 2000 00:00:00 GMT + 0100(CET) 在时区GMT + 0的API服务器上,如果检查数据库,我可以看到它是ISODate(“2000-01-05T23:00:00Z”) 如果我在服务器上尝试新date('2000-01-05T23:00:00Z'),我得到错误的dateWed Jan 05 2000 23:00:00 GMT + 0000(UTC) 当然,我的用户可以有不同的时区,所以将服务器时区设置为GMT + 1不会解决问题。 什么是正确的解决scheme? 发送date到服务器作为string,没有时区,并让它build立在插入之前的date? 还是有另一种方式?

在模型中使用buildToken不能用于环回

我试图开始编程一个Android应用程序的api,并希望使用node.js + loopback为此。 但我遇到了一些麻烦testing/学习语言。 下面的代码应该在我的数据库中生成新的用户(而且它),但是当我尝试用这个用户login没有AccessToken创build一个打印到控制台。 任何想法我做错了什么? 我的testing代码:create-test-data.js var app = require('./app'); var dataSource = app.dataSources.mysql; var loopback = require('loopback'); var User = loopback.User; // Getting User Model var AccessToken = loopback.AccessToken; // Getting AccessTokenModel /* Initializing the database done by this. If already exist it will clean it. dataSource.automigrate('user', function (err) {}); dataSource.automigrate('account', function (err) […]

SLC Loopback:使用模型钩子中的模型实例

使用loopback模型钩子,我知道你可以通过使用beforeCreate创build一个像User一样的模型实例。 User.beforeCreate = function(next, userInstance) { //your logic goes here using userInstance next(); }; 但是,如果我需要添加一些使用刚创build的用户的firstName的应用程序逻辑,我该怎么做呢? User.afterCreate = function(next) { //I need access to the user that was just created and some of it's properties next(); }; 有没有一种方法来获得刚刚创build的用户,还是需要更改我的应用程序逻辑以使用之前而不是之后?

Heroku npm版本与Strongloop buildpack

所以我有一个build立在loopback.io之上的项目。 我在package.json中指定了节点和npm版本。 但是,由于安装的一些奇怪的原因,服务器似乎仍然使用npm = 1.4.28。 还有什么我需要做的想法? 现在我假设是因为npm = 1.4.28,所以安装lodash会造成问题。 我做了平常的build设强大的heroku:heroku应用程序:创build–buildpack https://github.com/strongloop/strongloop-buildpacks.git "engines": { "node": "0.10.x", "npm": "2.x" } 而从GURS推heroku的日志 remote: remote: npm ERR! EEXIST, open '/app/.npm/ea4720da-app-npm-lodash-2-4-1-package-tgz.lock' remote: File exists: /app/.npm/ea4720da-app-npm-lodash-2-4-1-package-tgz.lock remote: Move it away, and try again. remote: remote: npm ERR! System Linux 3.13.0-40-generic remote: npm ERR! command "/tmp/build_bf55002725acbaa28a6caabb58f75a77/vendor/node/bin/node" "/tmp/build_bf55002725acbaa28a6caabb58f75a77/vendor/node/bin/npm" "install" "–production" remote: npm ERR! […]

使用afterRemote钩子在远程方法的环回中发送响应

我正在尝试处理需要发送邮件的请求。 为了响应请求而不等待邮件发送,我正在发送一个afterRemote钩子邮件。 该方法似乎运行正常,并发送邮件,但由于某种原因,cb函数不执行,因此在客户端请求保持未答复。 问题是在console.log("Here");cb(null,{});的代码,你可以看到我有console.log("Here");cb(null,{}); 那里和第一个命令得到执行,但不是看起来第二个。 user.joinEntity = function(data, cb) { var loopbackCtx = user.app.loopback.getCurrentContext(); var userId=loopbackCtx.accessToken.userId; if(false){ cb( new Error("Cant join that Entity."),{}); }else{ user.find({where:{id:userId}},function(err,applicant_instance){ if (err) cb(err,{}); if(applicant_instance.length>0) user.find({where:{id:data.ownerId}},function(err,founder_instance){ if (err) cb(err,{}); if(founder_instance.length>0) user.app.models.EntityApplication.create({email:applicant_instance[0].email,userId:userId,EntityFounder:founder_instance[0].id,Entity:data.id,Status:"pending"},function(err,Entity_Application_Instance){ if (err) cb(err,{}); loopbackCtx.join_entity={applicant:applicant_instance[0].email,entity:data.name,to:founder_instance[0].email}; console.log("Here"); cb(null,{}); }); }); }) } } user.afterRemote('joinEntity',function(){ var loopbackCtx = user.app.loopback.getCurrentContext(); user.app.models.Email.send({ to: loopbackCtx.join_entity.to, from: […]

无法使用StrongLoop Arc连接到StrongLoop PM

我无法使用StrongLoop Arc连接到StongLoop PM。 我遵循这些方向 。 这是我的尝试: # in one terminal window, I started up StrongLoop PM $ nvm install v0.12.4 $ nvm alias default 0.12.4 $ npm install -g strongloop $ slc loopback > name: hello-strongloop > directory: hello-strongloop $ cd hello-strongloop $ slc pm # in another new terminal window, I started Arc $ […]

StrongLoop / LoopBack:在其他连接器数据源模板上获得完整的jSON

我试图从谷歌地理编码API得到完整的json响应,所以我可以testing结果“状态”。 从文档: responsePath:应用于HTTP正文的可选JSONPath。 有关JSONpath的语法,请参阅https://github.com/s3u/JSONPath 。 所以我使用“responsePath”:“$ .. *”,但它得到的响应都搞砸了。 例: [ [ { "address_components":[ { "long_name":"Caracas", "short_name":"CCS", "types":[ "locality", "political" ] }, { "long_name":"Libertador", "short_name":"Libertador", "types":[ "administrative_area_level_2", "political" ] }, { "long_name":"Capital District", "short_name":"Dto. Capital", "types":[ "administrative_area_level_1", "political" ] }, { "long_name":"Venezuela", "short_name":"VE", "types":[ "country", "political" ] } ], "formatted_address":"Caracas, Venezuela", "geometry":{ "bounds":{ "northeast":{ "lat":10.5401335, "lng":-66.7179533 […]

无法从http:// localhost:3000 / sw-import.js / resources中读取Swagger JSON

我是新来的节点和大招,并正在通过loopback.io示例来尝试和build立一个API。 我的机器上安装了node,strongloop。 我创build了一个新的环回应用程序,并build立了一个快速的“用户”模型,并尝试运行swagger explorer来查看是否可以查看这些API。 但是,我运行localhost时出现以下错误:3000 / explorer / 有任何想法吗?

强循环(loopback)类方法

理解Strongloop模型的行为有些困难。 有很多关于静态和远程方法的文档,但是一般的类方法呢? 比方说,我有一个用户模型,它有一个显示全名的方法: module.exports = function (User) { User.name = function () { return User.firstname + ' ' + User.lastname; } }; 我如何获取这个用户并使用这个方法? 我会想: var User = app.models.User; User.findById('559103d66d', function (err, model) { console.log(model.name()); }); 但显然,findById返回一个包含所有属性而不是实际模型的JSON对象。 那么如何在Strongloop中定义和使用模型方法呢?

父母关系中的强环性

我不知道我是否只是盲目或什么,但我怎么能做到以下几点: 我有一个与UserData模型hasOne关系的User模型。 我只想在User的结果中直接使用UserData一个属性。 User的关系如下所示: "relations": { "userData": { "type": "hasOne", "model": "UserData" } } 而User的默认范围: "scope": { "include": "userData" } 所以一个User的结果是: [ { "id": 5, "email": "example@example.com", "name": "Example", "userData": { "id": 5, "birthdate": "1971-09-06T00:00:00.000Z" } } ] 但是我想要的是这样的: [ { "id": 5, "email": "example@example.com", "name": "Example", "birthdate": "1971-09-06T00:00:00.000Z" } ] 我怎样才能做到这一点? 编辑: 这两个模型定义: ChiliUser […]