I have a simple route thing like this in node using connect (source/routes.js):
exports.routes = function(app) {
app.get('/data', function(req, res, params) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.write('Authenticated: ' + connect.session.auth + '\n');
res.end('app.get /data');
});
}
Starting the app (app.js):
var routes = require('connect');
var routes = require('./source/routes');
var server = connect.createServer(
connect.cookieParser(),
connect.session({ secret: 'justmeknowsthis', cookie: { maxAge: config.data.sessionTimeout }}),
connect.router(routes.routes)
);
server.listen(3000);
What I want to be able to do is:
app.get('/data*', function(...
I determine what data to return by parsing the url.
I have a simple route thing like this in node using connect (source/routes.js):
exports.routes = function(app) {
app.get('/data', function(req, res, params) {
res.writeHead(200, { 'Content-type': 'text/plain' });
res.write('Authenticated: ' + connect.session.auth + '\n');
res.end('app.get /data');
});
}
Starting the app (app.js):
var routes = require('connect');
var routes = require('./source/routes');
var server = connect.createServer(
connect.cookieParser(),
connect.session({ secret: 'justmeknowsthis', cookie: { maxAge: config.data.sessionTimeout }}),
connect.router(routes.routes)
);
server.listen(3000);
What I want to be able to do is:
app.get('/data*', function(...
I determine what data to return by parsing the url.
Share Improve this question edited Nov 18, 2011 at 11:51 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Nov 18, 2011 at 11:44 AskenAsken 8,08110 gold badges49 silver badges82 bronze badges1 Answer
Reset to default 9First of all, the router middleware has been removed from Connect, so you can either use Express or make your own router to be safer for the future ( see this mit: https://github./senchalabs/connect/mit/2ca7ec3ff64cb7600bfd029233228236bf048671 ).
If you choose to use Express, you can pass in a regular expression for the route (more info here: http://expressjs./guide.html#routing), but I would use something like this instead (for your specific case):
app.get('/data/:type', function (req, res) {
console.log('Received ' + req.params.type + ' data');
});