Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why do I to have prefix all my route handlers

Why do I to have prefix all my route handlers

Problem

I'm creating an application using Expressjs running on node under IISNode (i.e on windows).

I start by setting things up very much like all the expressjs examples I've seen:

  backend.configure(function() {
    backend.register('html', {
      compile: function(str, options) {
        return function(locals) {
          return str;
        };
      }
    });
    backend.set('views', __dirname + '/views');
    backend.set('view engine', 'html');
    backend.set('view options', {
      layout: false
    });
    backend.use(express.bodyParser());
    backend.use(backend.router);
    backend.use(express.static(__dirname + '/public'));
  });  

Lets say my site is running at localhost://mysite. I'm having to create all my Route Handlers as follows.

  backend.get('/mysite/index', function(req, res, next) {
    return res.render('index');
  });

i.e. I'm having to Prefix them all with "mysite". Non of the examples I've seen require this. Is this something to do with IISNode or something else I haven't configured?

Problem courtesy of: Simon Lomax

Solution

Out of the box, this is indeed how you have to do it. You could look into express-resource, enabling resourceful routing - but that comes with it's own caveats, at least when it comes to route-specific middleware.

If it's just one path, I think you can handle that with app.set("basepath", "mysite").

Solution courtesy of: Linus Gustav Larsson Thiel

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Why do I to have prefix all my route handlers

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×