aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-07-01 03:26:26 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-07-01 03:26:26 +0200
commitc66f8be25f230f8fcea2774e54a56ad43fba9b58 (patch)
treed20130f43292ff0322afcc71b9fcbf41e076fd93 /app.js
parent02588ca7aa174c5b4c95c8f124eb8086042f9538 (diff)
downloadexample-collection-json-db-c66f8be25f230f8fcea2774e54a56ad43fba9b58.tar.gz
example-collection-json-db-c66f8be25f230f8fcea2774e54a56ad43fba9b58.tar.bz2
example-collection-json-db-c66f8be25f230f8fcea2774e54a56ad43fba9b58.tar.xz
example-collection-json-db-c66f8be25f230f8fcea2774e54a56ad43fba9b58.zip
o Adding paging.
o Adding new root resource.
Diffstat (limited to 'app.js')
-rw-r--r--app.js20
1 files changed, 15 insertions, 5 deletions
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(){