diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-06-30 01:15:10 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-06-30 01:15:10 +0200 |
commit | d8d4a98be0a022cea96f16e73988917df6896c20 (patch) | |
tree | d56e77e9f28283b78853374d589360ee3dbc817a /app.js | |
parent | 7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9 (diff) | |
download | example-collection-json-db-d8d4a98be0a022cea96f16e73988917df6896c20.tar.gz example-collection-json-db-d8d4a98be0a022cea96f16e73988917df6896c20.tar.bz2 example-collection-json-db-d8d4a98be0a022cea96f16e73988917df6896c20.tar.xz example-collection-json-db-d8d4a98be0a022cea96f16e73988917df6896c20.zip |
o Adding views for all departments, department, employees in department and employee in both HTML and Collection+JSON variants.
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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(){ |