I'm sending a file from client-side to server side using XHR:
$(document).on('drop', function(dropEvent) {
dropEvent.preventDefault();
_.each(dropEvent.originalEvent.dataTransfer.files, function(file) {
// ...
xhr.open('POST', Router.routes['upload'].path(), true);
xhr.send(file);
});
})
Now I want to respond to this POST server-side and save the file to disk. The docs only seems to talk about handling things client-side; I don't even know how to get a hook on the server-side.
All I have for routes right now is this:
Router.map(function() {
this.route('home', {
path: '/'
});
this.route('upload', {
path: '/upload',
action: function() {
console.log('I never fire');
}
});
});
With connect, I could do:
Connect.middleware.router(function(route) {
route.post('/upload', function(req, res) {
// my server-side code here
});
});
Is there anything similar for Iron-Router?
Digging through the internals, I discovered Meteor is using connect
under the hood, and I can do something like this:
WebApp.connectHandlers.use(function(req, res, next) {
if(req.method === 'POST' && req.url === '/upload') {
res.writeHead(200);
res.end();
} else next();
});
But I have no idea how to get the user in this context.