How to respond server-side to routes using Meteor and Iron-Router?

后端 未结 4 1517
无人共我
无人共我 2021-01-27 04:34

I\'m sending a file from client-side to server side using XHR:

$(document).on(\'drop\', function(dropEvent) {
    dropEvent.preventDefault();
    _.each(dropEven         


        
4条回答
  •  别那么骄傲
    2021-01-27 05:02

    By default, your routes are created as client side routes. This means, a link to that route will be handled in the browser vs. making a server request. But you can also create server side routes by providing a where option to the route. The handler for the server side route exposes the request, response, and next properties of the Connect object. The syntax has changed a little from 0.5.4 to the dev branch so I'll provide both examples depending on which you're using:

    v0.5.4

    Router.map(function () {
      this.route('upload', {
        where: 'server',
        handler: function () {
          var request = this.request;
          var response = this.response;
          // do whatever
        }
      });
    });
    

    dev

    Router.map(function () {
      this.route('upload', {
        where: 'server',
        action: function () {
          var request = this.request;
          var response = this.response;
          // do whatever
        }
      });
    });
    

提交回复
热议问题