I see strange behavior when trying to add a PDF file.
The following code in the if statement throws: like \ routes.js
Router.onBeforeAction(function () { if (!Meteor.user() || Meteor.loggingIn()) { this.redirect('welcome.view'); } else { Meteor.call("userFileDirectory", function (error, result) { if (error) throw error; else console.log(result); }); this.next(); } }, { except: ['welcome.view'] });
Error: Meteor.userId can only be called by calling a method. using this.userId in the publish function. in Object.Meteor.userId (packages / accounts-base / accounts_server.js: 19: 1) in Object.Meteor.user (packages / accounts-base / accounts_server.js: 24: 1) in [object Object] .Router. onBeforeAction.except (application / both / 3-router / routes.js: 10: 15) into packages / hardware: router / lib / router.js: 277: 1 at [object Object] ._. Extend.withValue (packages / meteor / dynamic_nodejs.js: 56: 1) in the Object.hookWithOptions object (packages / hardware: router / lib / router.js: 276: 1) in boundNext (packages / hardware: middleware-stack / lib /middleware_stack.js: 251: 1) on runWithEnvironment (packages / meteor / dynamic_nodejs.js: 108: 1) with packages / meteor / dynamic _nodejs.js: 121: 1 in [object Object] .dispatch (Packages / iron: intermediate stack / Library / middleware _stack.js: 275: 1)
Only when I add this code to the file and the / pdf route is taken:
Router.route('/pdf', function() { var filePath = process.env.PWD + "/server/.files/users/test.pdf"; console.log(filePath); var fs = Npm.require('fs'); var data = fs.readFileSync(filePath); this.response.write(data); this.response.end(); }, { where: 'server' });
The above code is working fine; pdf is displayed on the screen and no exception occurs when I take out the code onBeforeAction.
The opposite is also true, if I choose the server route, there is no path that throws an exception.
Aaron source share