Is it possible to define iron-router server side routes that respond to certain HTTP actions?

前端 未结 1 939
时光说笑
时光说笑 2021-01-21 12:59

I have a basic server side route defined in iron-router like:

this.route(\'foo\', {
  where: \'server\',
  path: \'/foo\',
  action: function() {
    // handle r         


        
1条回答
  •  一生所求
    2021-01-21 13:58

    You can definitely check the method and only respond if it's the one you want, e.g., like this:

    Router.map(function () {
        this.route('route', {
            path: '/mypath',
            where: 'server',
            action: function() {
                if (this.request.method != 'GET') {
                    // do whatever
                } else {
                    this.response.writeHead(404);
                }
            }
        })
    });
    

    The second question beats me. It might be possible to use this.next() somehow, but I'm not sure.

    0 讨论(0)
提交回复
热议问题