Skip to content

Instantly share code, notes, and snippets.

@jedahan
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedahan/ef5fcff1fb7e4ad7500c to your computer and use it in GitHub Desktop.
Save jedahan/ef5fcff1fb7e4ad7500c to your computer and use it in GitHub Desktop.
how to refactor to use middleware?
# GET /participants
app.get '/participants', parseTimestamp, ->
options = timestamp: $gte: (+ @query?.start or 0)
@body = mustache.render table_template, participants: yield participants.find(options)
# GET /participants.json
app.get '/participants.json', parseTimestamp, ->
options = timestamp: $gte: (+ @query?.start or 0)
@body = yield participants.find(options)
# GET /participants.csv
app.get '/participants.csv', parseTimestamp, ->
options = timestamp: $gte: (+ @query?.start or 0)
@body = yield json2csv data: yield participants.find(options)
app.get('/participants', parseTimestamp, function*() {
var options = {
timestamp: {
$gte: +(this.query.start || 0)
}
};
return this.body = mustache.render(table_template, {
participants: (yield participants.find(options))
});
});
app.get('/participants.json', parseTimestamp, function*() {
var options = {
timestamp: {
$gte: +(this.query.start || 0)
}
};
return this.body = (yield participants.find(options));
});
app.get('/participants.csv', parseTimestamp, function*() {
var options = {
timestamp: {
$gte: +(this.query.start || 0)
}
};
return this.body = (yield json2csv({
data: (yield participants.find(options))
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment