流星服务器端用铁路由器登录

时间:2014-11-18 23:01:16

标签: login meteor iron-router

我想创建一个服务器端登录,为我的客户端应用程序使用铁路由器:服务器。 但直到现在我还没有找到任何线索如何做到这一点。然而,我使用reststop2,但现在他说要使用铁路由器。

这是我的简单代码:

Router.route('/api/signin', {where: 'server'})
    .get(function () {
        this.response.end('get request\n');
    })
    .post(function () {
        console.log(this.request.body.username);//or email maybe
        console.log(this.request.body.password);
        this.response.end('post request\n');
    });

我使用身体的json发送或发布数据,这就是为什么我使用this.request.body.*

现在让我知道,如何使用该用户名和密码登录服务器端?

仅供参考,在reststop2中我只使用localhost:3000/api/login并发送数据用户名和密码,之后我将返回access tokenuser id

感谢

2 个答案:

答案 0 :(得分:1)

您可以使用iron:router来构建API:

Router.map(function () {
    this.route('/api/login/:username/:password', {
        where : 'server,
        action : function(){
            //your code goes here
        }
    }
});

我总是选择一个实现API而不是铁的包:路由器,但对于简单的服务器端东西,铁路:路由就可以了。

答案 1 :(得分:0)

我发布了一个用于在Meteor 0.9.0+中编写REST API的开源软件包,我认为它可能正是您所寻找的。不推荐使用RestStop2时,我遇到了同样的问题:

https://github.com/krose72205/meteor-restivus

它受到RestStop2的启发,并使用Iron Router的服务器端路由构建。如果您已经在使用RestStop2,那么很容易转换为。