Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse url for getting params in a Rendr server middleware ? #351

Open
ghost opened this issue Mar 27, 2014 · 3 comments
Open

How to parse url for getting params in a Rendr server middleware ? #351

ghost opened this issue Mar 27, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2014

No description provided.

@lo1tuma
Copy link
Member

lo1tuma commented Mar 27, 2014

I don't understand the question.

@ghost
Copy link
Author

ghost commented Mar 27, 2014

I have a Rendr middleware which load data for my application but I want to parse the parameters of the request for having the params array like in controllers.

var LocationsService = require('../../services/locations'),
    PlacesService = require('../../services/places');

/**
 * Middleware for data used by application
 */
module.exports = function(req, res, next) {
    var app = req.rendrApp;

    LocationsService.getLocationBySlug(app, 'paris-france', function(err, locationResult) {
      if (err) {
        return next(err);
      }

      var location = locationResult.location;

      PlacesService.getPlacesByLocation(app, location.id, function(err, placesResult) {
        if (err) {
          return next(err);
        }

        var places = placesResult.places;

        app.set('location', location);
        app.set('places', places);
        next();
      });
    });
};

@bigethan
Copy link
Contributor

bigethan commented Apr 2, 2014

the middleware runs before the router, so I don't think this is possible. We accomplish something very similar to this by adding the data to this.app in app.js's postInitialize method. For your case you could have a default controller that has a method you call from each of them to set the location/place data based on the params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants