Created
July 28, 2013 23:40
-
-
Save ShakataGaNai/6100743 to your computer and use it in GitHub Desktop.
Based on http://chimera.labs.oreilly.com/books/1234000001808/ch07.html#settinguproutes_with_express + comments for https://github.com/braindamageinc/SublimeHttpRequester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
// http://localhost:9001/users/1 | |
app.get('/users/:id', function(req, res, next){ | |
var id = req.params.id; | |
if (checkPermission(id)) { | |
res.send("private"); | |
} else { | |
next(); | |
} | |
}); | |
// http://localhost:9001/users/2 | |
app.get('/users/:id', function(req, res){ | |
res.send("public"); | |
}); | |
app.listen(9001); | |
function checkPermission(id){ | |
if(id == 1){ | |
return true; | |
}else{ | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment