标签: iron-router

铁路由器服务器端的Meteor.user()

如何在服务器端路由上检查用户是否已登录?

我会在'之前'添加检查,但是Metor.user()在这里不起作用.

提前致谢.

ps我发现如何让Meteor.user()返回服务器端?,但不适用于铁路由器

meteor iron-router

9
推荐指数
1
解决办法
1654
查看次数

使用Iron Router进行waitOn订阅,该订阅依赖于来自其他订阅的文档的数据

我在配置waitOn路由的一部分时遇到问题,其中一个订阅的参数由来自不同订阅的文档中的值确定.

游戏中的收藏品是候选人和访谈.面试将只有一名候选人.这是一些示例数据:

candidate = {
    _id: 1
    firstName: 'Some',
    lastName: 'Developer'
    //other props
};

interview = { 
    _id: 1,
    candidateId: 1
    //other props
};
Run Code Online (Sandbox Code Playgroud)

路由配置如下.

this.route('conductInterview', {
    path: '/interviews/:_id/conduct', //:_id is the interviewId
    waitOn: function () {
        return [
            Meteor.subscribe('allUsers'),
            Meteor.subscribe('singleInterview', this.params._id),
            // don't know the candidateId to lookup because it's stored
            // in the interview doc
            Meteor.subscribe('singleCandidate', ???), 
            Meteor.subscribe('questions'),
            Meteor.subscribe('allUsers')
        ];
    },
    data: function () {
        var interview = Interviews.findOne(this.params._id);
        return {
            interview: interview,
            candidate: Candidates.findOne(interview.candidateId);
        }; …
Run Code Online (Sandbox Code Playgroud)

meteor iron-router

9
推荐指数
2
解决办法
1558
查看次数

如何从meteor访问HTTP POST数据?

我有一个Iron-router路由,我希望通过HTTP POST请求接收lat/lng数据.

这是我的尝试:

Router.map(function () {
  this.route('serverFile', {
    path: '/receive/',
    where: 'server',

    action: function () {
      var filename = this.params.filename;
      resp = {'lat' : this.params.lat,
              'lon' : this.params.lon};
      this.response.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
      this.response.end(JSON.stringify(resp));
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

但是查询服务器:

curl --data "lat=12&lon=14" http://127.0.0.1:3000/receive
Run Code Online (Sandbox Code Playgroud)

退货{}.

也许params不包含发布数据?我试图检查对象和请求,但我找不到它.

api json http-post meteor iron-router

8
推荐指数
1
解决办法
6748
查看次数

如何在Iron Router blaze集成上正确替换this.stop()with pause()

当我将Iron Router升级到blaze集成分支时,我开始收到此警告:

"You called this.stop() inside a hook or your action function but you should use pause() now instead" 
Run Code Online (Sandbox Code Playgroud)

Chrome控制台 - > iron-router.js:2104 - > client/route_controller.js:193 from package

代码在客户端:

Router.before(mustBeSignedIn, {except: ['userSignin', 'userSignup', 'home']});

var mustBeSignedIn = function () {
    if (!Meteor.user()) {
        // render the home template 
        this.redirect('home');
        // stop the rest of the before hooks and the action function 
        this.stop();
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我试着更换this.stop()同:pause(),Router.pause()this.pause(),但仍然无法正常工作.另外我还没有在铁路由器包上找到暂停功能.

如何正确更换this.stop()用 …

meteor iron-router

8
推荐指数
2
解决办法
2266
查看次数

Meteor Iron-router服务器端只有路由如何获取当前用户?

对于仅服务器路由,如何获取当前用户.

请注意这是一条看起来像这样的路线:

    this.route('report_access', {
      path: '/report/:humanId?/:reportKey',
      where: 'server',
      action: ....
   });
Run Code Online (Sandbox Code Playgroud)

这不在发布或方法调用中,因此Meteor.user()/ Meteor.userId()失败.

我查看了route.params并且没有设置用户ID.

meteor iron-router

8
推荐指数
2
解决办法
1934
查看次数

我应该在路由逻辑或流星模板助手中提供数据吗?

例:

我正在编写一个处理博客帖子列表的Meteor应用程序.所有博客文章都存储在名为"帖子"的集合中.我使用Iron Router进行路由.

我想向用户显示特定作者创建的所有帖子的列表.此列表将使用Spacebars显示.因此,我需要向模板提供数据.

问题:

据我所知,有两种方法可以做到这一点:

  1. 使用模板助手
  2. 使用我的路线的'data'属性

选项1示例:

Template.postList.helpers({
postsToDisplay: function(){
    return Posts.find({author: 'someAuthor'});
}
})
Run Code Online (Sandbox Code Playgroud)

选项2示例:

//Inside my route
data: function(){
    return {postsToDisplay: Posts.find({author: 'someAuthor'})};
}
Run Code Online (Sandbox Code Playgroud)

这两种方法之间是否存在显着差异?是否有理由偏爱另一个?有人提供更好的表现吗?

非常感谢您的回答!

performance routing meteor iron-router spacebars

8
推荐指数
1
解决办法
380
查看次数

如何做一个流星铁路由器服务器端重定向?

给出类似的东西

Router.route('/blah/:stuff', function () {
  // respond with a redirect
}, {where: 'server'});
Run Code Online (Sandbox Code Playgroud)

怎么做重定向?内置了什么?还是我必须自己制作?

这是使用Meteor 1.0/Iron Router 1.0

meteor iron-router

8
推荐指数
1
解决办法
2396
查看次数

如何使用meteor帐户和autoform添加/编辑用户

我正在构建Meteor管理系统的一部分,让管理员添加/编辑其他管理员.我正在使用Meteor Accounts和Autoform,但我无法弄清楚如何处理它以便用户通过Autoform进行验证并正确保存.从我发现它看起来我需要使用该Accounts.createUser方法并使表单成为一个type="method"或什么,但我不知道如何处理或如果这是正确的方式.

这是我现在的代码:

架构:

Schema = {};

Schema.UserProfile = new SimpleSchema({
    name: {
        type: String,
        label: "Name"
    }
});

Schema.User = new SimpleSchema({
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    password: {
      type: String,
      label: "Password",
      min: 6
    },
    passwordConfirmation: {
      type: String,
      min: 6,
      label: "Password Confirmation",
      custom: function() {
        if (this.value !== this.field('password').value) {
          return "passwordMissmatch";
        }
      }
    },
    createdAt: {
      type: Date,
      autoValue: function() {
        if (this.isInsert) {
          return new Date;
        } else …
Run Code Online (Sandbox Code Playgroud)

meteor iron-router meteor-accounts meteor-autoform

8
推荐指数
1
解决办法
2955
查看次数

如何摆脱Iron Router启动页面

我有一个Meteor应用程序,我正在使用铁:路由器包.当我部署到meteor.com并且当我在本地开发时,一个铁路由器启动页面显示在页面上,其中包含"组织您的流星应用程序".我怎么能摆脱这个?我尝试了很多东西,但似乎没有任何帮助.

谢谢

javascript meteor iron-router

8
推荐指数
1
解决办法
1762
查看次数

使用铁路由器路由到Meteor autoform提交的新数据?

我正在使用Meteor与AutoForm和铁路由器.

我有一个用于插入数据的autoform,我想重定向到成功插入后添加的数据页面.我该怎么办?

这是For:

{{#autoForm collection="Products" id="add" type="insert"}}
    <h4 class="ui dividing header">Products Information</h4>
      {{> afQuickField name='name'}}
      {{> afQuickField name='info'}}
    <button type="submit" class="ui button">Insert</button>
{{/autoForm}}
Run Code Online (Sandbox Code Playgroud)

铁路由器:

Router.route('/products/:_id', {
  name: 'page',
  data: function() { return Products.findOne(this.params._id);}
});
Run Code Online (Sandbox Code Playgroud)

回调/钩

AutoForm.hooks({
  add: {
    onSuccess: function(doc) {
      Router.go('page', ???);
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

meteor iron-router meteor-autoform

8
推荐指数
1
解决办法
2122
查看次数