mjackson / mach

HTTP for JavaScript
810 stars 41 forks source link

RegExp routing and capture groups #31

Closed lucadom closed 9 years ago

lucadom commented 10 years ago

Hello, after the breaking changes made with commit https://github.com/mjackson/mach/commit/90c8dd733d0de6bc699d02227f49ef346d0ac158 i can no longer find the routing RegExp capture groups. As stated in https://github.com/mjackson/mach/wiki/Request-Dispatch#routing-path-based-dispatch they should be inside request.route, but it's always undefined:

var mach = require('mach');
var app = mach.stack();

app.use(mach.params);

app.get('/named/:param', function (request) {
  return "param was " + request.params.param;
});

app.route(/\/regex\/(\d+)/, function (request) {
  return "param was "; // where it is? request.route is undefined...
});

// BEFORE
// app.get(/\/regex\/(\d+)/, function (request, param) {
//   return "param was " + param;
// });

mach.serve(app, 3000);
mjackson commented 9 years ago

Hi @lucadom! Apologies for the breaking change, but you can't use named parameters with regular expressions anymore. Quite a few things changed in recent months due to the push toward 1.0. Once we release a stable 1.0, the API will follow semver.