logo
down
shadow

Server side routes in Iron Router and Meteor


Server side routes in Iron Router and Meteor

By : user2955630
Date : November 22 2020, 10:40 AM
this one helps. Your server-side routes are running the global onBeforeAction code (it's defined in a shared directory), which breaks because the server routes are simple REST endpoints which don't understand user authentication information (i.e. Meteor.user() doesn't work). The solution is to wrap the client-specific onBeforeAction calls with Meteor.isClient or simply move that code under the client directory. For example:
code :
if (Meteor.isClient) {
  Router.onBeforeAction(function () {
    if (!Meteor.user() || Meteor.loggingIn())
      this.redirect('welcome.view');
    else
      this.next();
    }
    ,{except: 'welcome.view'}
  );

  Router.onBeforeAction(function () {
    if (Meteor.user())
      this.redirect('home.view');
    else
      this.next();
    }
    ,{only: 'welcome.view'}
  );
}

Router.route('/pdf-server', function() {
  ...
}, {where: 'server'});


Share : facebook icon twitter icon
Meteor.user() on iron-router server side

Meteor.user() on iron-router server side


By : Piyush Bajpai
Date : March 29 2020, 07:55 AM
wish helps you I'm afraid that this is not possible. I guess that the problem comes from the fact that you're trying to connect to the server with two different protocols - both literally and in logically - so there is no obvious way to relate this two actions.
There is, however, a pretty simple solution that may suit your needs. You'll need to develop a simple system of privileges tokens, or secret keys, or whatever you call them. First, create a server method
code :
var Secrets = new Meteor.Collection("secrets"); // only on server!!!

Meteor.methods({
  getSecretKey: function () {
    if (!this.userId)
      // check if the user has privileges
      throw Meteor.Error(403);
    return Secrets.insert({_id: Random.id(), user: this.userId});
  },
});
Meteor Iron Router server-side hooks

Meteor Iron Router server-side hooks


By : Will Wang
Date : March 29 2020, 07:55 AM
wish of those help Iron Router is just the same both on client and server and the declarations can be done on a directory/file which is available to both client and the server.
By default, the declared routes are for the client. If you want a route to be server side, then you explicitly declare so by including where: 'server'.
code :
Router.map(function () {
  this.route('serverRoute', {
    where: 'server',

    action: function () {
      // some special server side properties are available here
    }
  });
});
Router.map(function () {
  this.route('serverFile', {
    where: 'server',
    path: '/files/:filename',

    action: function () {
      var filename = this.params.filename;

      this.response.writeHead(200, {'Content-Type': 'text/html'});
      this.response.end('hello from server');
    }
  });
});
Router.before(someFilter, {only: ['clientRoute1', 'clientRoute2', 'serverRoute1']});
Router.before(someOtherFilter, {except: ['clientRoute3', 'clientRoute4', 'serverRoute2']});
Using Iron Router on Server Side of Meteor Application?

Using Iron Router on Server Side of Meteor Application?


By : user3289254
Date : March 29 2020, 07:55 AM
will be helpful for those in need Your suggestion is the good choice to make. You can't catch the Router in a Meteor method because it's server side. You have to do it in the callback function, exactly like you suggested :
code :
Meteor.call('createNewItinerary',itinerary, function(err, data){
   if(err){
     console.log(err);
   }
   Router.go('confirmation');
 });
 throw new Meteor.Error( 500, 'There was an error processing your request' );
How to respond server-side to routes using Meteor and Iron-Router?

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


By : Paul Ward
Date : March 29 2020, 07:55 AM
I wish this help you 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
Best way to cache client-side data across iron-router routes in Meteor

Best way to cache client-side data across iron-router routes in Meteor


By : ZestyBurrito
Date : March 29 2020, 07:55 AM
it fixes the issue It sounds like you need to use subs-manager.
Related Posts Related Posts :
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • How to animate the width of a div slowly with jquery
  • JavaScript + RegEx Complications- Searching Strings Not Containing SubString
  • SignalR - Unable to get property 'client' of undefined or null reference
  • full calendar not displaying when loaded (with backbone)
  • Angular: Update service and share data between controllers
  • ReplaceAll Google script
  • Search for matching LI items in separate UL
  • Access arguments of an... argument
  • Customizing Google custom search jsapi (query strings)
  • React | Can´t load Images > Module not found
  • Dynamically creating buttons in DOJO
  • 404 Not Found in AJAX post call
  • How do I find out, using javascript, what software opened and running my application?
  • Javascript to check the status of wireless connection
  • StarDict support for JavaScript and a Firefox OS App
  • Phonegap event Resume
  • call javascript function on ENTER key press?
  • When is the best time to remove no-js classes from the html tag
  • Recommended email sending languages
  • setInterval not working properly with chrome
  • Does IE create new scope for each script tag?
  • Uncaught SyntaxError: Unexpected token < Underscore and parse issues
  • How to pass captured URL to Email Body in HTML
  • How to structure default nested resources?
  • Store all the keys of a JSON object in a variable
  • Need an efficient way to group the Array of object in javascript
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org