diff options
author | Mark Engel <mark.c.engel@gmail.com> | 2011-01-21 15:26:47 +0100 |
---|---|---|
committer | Mark Engel <mark.c.engel@gmail.com> | 2011-01-21 15:26:47 +0100 |
commit | ef31bee06ce4517e83de01f9f13f6c96a77a0b5f (patch) | |
tree | e05d91688134e6363d983c67ee43fe28e86ead01 /src/nodejs/no2.js | |
parent | 6ed48d9e3c9ee669d25323fb547acaeff2194437 (diff) | |
parent | 3278c8de34e026421a7908dbdc5c96f8226bc0ca (diff) | |
download | osm-xapi-ef31bee06ce4517e83de01f9f13f6c96a77a0b5f.tar.gz osm-xapi-ef31bee06ce4517e83de01f9f13f6c96a77a0b5f.tar.xz osm-xapi-ef31bee06ce4517e83de01f9f13f6c96a77a0b5f.zip |
Merge branch 'master' of github.com:slomo/osm-spline-xapi
Diffstat (limited to 'src/nodejs/no2.js')
-rw-r--r-- | src/nodejs/no2.js | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/src/nodejs/no2.js b/src/nodejs/no2.js deleted file mode 100644 index 233b5e1..0000000 --- a/src/nodejs/no2.js +++ /dev/null @@ -1,106 +0,0 @@ -var users = [ - { name: 'tj' }, - { name: 'tim' } -]; - -function user(app) { - app.resource('/.:format?', { - 'get' : function(req, res, next) { - switch (req.params.format) { - case 'json': - var body = JSON.stringify(users); - res.writeHead(200, { - 'Content-Type': 'application/json', - 'Content-Length': body.length - }); - res.end(body); - break; - default: - var body = '<ul>' - + users.map(function(user) { - return '<li>' + user.name + '</li>'; - }).join('\n') - + '</ul>'; - res.writeHead(200, { - 'Content-Type': 'text/html', - 'Content-Length': body.length - }); - res.end(body); - } - } - }); - - app.resource('/:id.:format', { - 'get' : function(req, res, next) { - var user = users[req.params.id]; - if (user && req.params.format === 'json') { - user = JSON.stringify(user); - res.writeHead(200, { - 'Content-Type': 'application/json', - 'Content-Length': user.length - }); - res.end(user); - } - else { - // When true is passed, provide control - // back to middleware, skipping route - // match attemps - next(true); - } - } - }) - - app.resource('/\\[:id/:op?', { - 'get' : function(req, res) { - var body = users[req.params.id] - ? users[req.params.id].name - : 'User ' + req.params.id + ' does not exist'; - body = (req.params.op || 'view') + 'ing ' + body; - res.writeHead(200, { - 'Content-Type': 'text/html', - 'Content-Length': body.length - }); - res.end(body, 'utf8'); - } - }) -} - - -function main(app) { - app.resource('/', { - 'get' : function(req, res) { - var examples = [ - '/users', - '/users.json', - '/users/0 (or /users/0/view)', - '/users/0/edit', - '/users/0.json' - ]; - var body = 'Visit one of the following: <ul>' - + examples.map(function(str) { - return '<li>' + str + '</li>' - }).join('\n') - + '</ul>'; - res.writeHead(200, { - 'Content-Type': 'text/html', - 'Content-Length': body.length - }); - res.end(body, 'utf8'); - } - }); -} - - -var connect = require('connect'); -var resource = require('resource-router'); - -var server = connect.createServer( - connect.logger({ buffer: true }), - connect.cache(), - connect.gzip() - ); - -server.use('/users', resource(user)); -server.use(resource(main)); -server.listen(3000); -console.log('Connect server listening on port 3000'); |