From d8d4a98be0a022cea96f16e73988917df6896c20 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 30 Jun 2012 01:15:10 +0200 Subject: o Adding views for all departments, department, employees in department and employee in both HTML and Collection+JSON variants. --- app.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app.js') diff --git a/app.js b/app.js index a2e82ce..54dbd44 100644 --- a/app.js +++ b/app.js @@ -12,6 +12,7 @@ app.configure(function(){ app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); + app.use(urlgenerator); app.use(app.router); app.use(express.static(__dirname + '/public')); }); @@ -20,8 +21,28 @@ app.configure('development', function(){ app.use(express.errorHandler()); }); +function urlgenerator(req, res, next) { + var host = req.headers.host; + res.urlgenerator = { + departments: function() { + return 'http://' + host + '/'; + }, + department: function(dept_no) { + return 'http://' + host + '/department/' + dept_no; + }, + employees_in_department: function(dept_no) { + return 'http://' + host + '/department/' + dept_no + '/employees'; + }, + employee: function(emp_no) { + return 'http://' + host + '/employee/' + emp_no; + } + }; + next(); +} + app.get('/', routes.departments); app.get('/department/:dept_no', routes.department); +app.get('/department/:dept_no/employees', routes.employees_in_department); app.get('/employee/:emp_no', routes.employee); http.createServer(app).listen(app.get('port'), function(){ -- cgit v1.2.3