From c66f8be25f230f8fcea2774e54a56ad43fba9b58 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 1 Jul 2012 03:26:26 +0200 Subject: o Adding paging. o Adding new root resource. --- app.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'app.js') diff --git a/app.js b/app.js index 54dbd44..6f3f4cf 100644 --- a/app.js +++ b/app.js @@ -14,7 +14,7 @@ app.configure(function(){ app.use(express.methodOverride()); app.use(urlgenerator); app.use(app.router); - app.use(express.static(__dirname + '/public')); + app.use(express.static(__dirname + '/public', {maxAge: 60 * 60 * 1000})); }); app.configure('development', function(){ @@ -24,14 +24,22 @@ app.configure('development', function(){ function urlgenerator(req, res, next) { var host = req.headers.host; res.urlgenerator = { - departments: function() { + start: function() { return 'http://' + host + '/'; }, + + departments: function(offset) { + return 'http://' + host + '/department/' + (offset ? '?offset=' + offset : ''); + }, department: function(dept_no) { return 'http://' + host + '/department/' + dept_no; }, - employees_in_department: function(dept_no) { - return 'http://' + host + '/department/' + dept_no + '/employees'; + employees_in_department: function(dept_no, offset) { + return 'http://' + host + '/department/' + dept_no + '/employees' + (offset ? '?offset=' + offset : ''); + }, + + employees: function(offset) { + return 'http://' + host + '/employee/' + (offset ? '?offset=' + offset : ''); }, employee: function(emp_no) { return 'http://' + host + '/employee/' + emp_no; @@ -40,9 +48,11 @@ function urlgenerator(req, res, next) { next(); } -app.get('/', routes.departments); +app.get('/', routes.index); +app.get('/department', routes.departments); app.get('/department/:dept_no', routes.department); app.get('/department/:dept_no/employees', routes.employees_in_department); +app.get('/employee', routes.employees); app.get('/employee/:emp_no', routes.employee); http.createServer(app).listen(app.get('port'), function(){ -- cgit v1.2.3