Created
January 18, 2010 00:26
-
-
Save joshbuddy/279688 to your computer and use it in GitHub Desktop.
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
require('./lib/sherpa') | |
var sys = require("sys"), http = require("http"); | |
http.createServer(new Sherpa.interfaces.NodeJs([ | |
['/hello', function (request, response) { | |
response.sendHeader(200, {"Content-Type": "text/plain"}); | |
response.sendBody("Hello World\n"); | |
response.finish(); | |
}], | |
['/hello/:name', {matchesWith: {name: /^\d+$/}}, function (request, response) { | |
response.sendHeader(200, {"Content-Type": "text/plain"}); | |
response.sendBody("Hello Number "+request.sherpaResponse.params['name']+"\n"); | |
response.finish(); | |
}], | |
['/hello/:name', function (request, response) { | |
response.sendHeader(200, {"Content-Type": "text/plain"}); | |
response.sendBody("Hello "+request.sherpaResponse.params['name']+"\n"); | |
response.finish(); | |
}], | |
['/hello/:name', {conditions:{method: 'POST'}}, function (request, response) { | |
response.sendHeader(200, {"Content-Type": "text/plain"}); | |
response.sendBody("Hello POSTY "+request.sherpaResponse.params['name']+"\n"); | |
response.finish(); | |
}], | |
['not found', function (request, response) { | |
response.sendHeader(404, {"Content-Type": "text/plain"}); | |
response.sendBody("I can't find what you're looking for.."); | |
response.finish(); | |
}] | |
]).listener()).listen(8000); | |
sys.puts("Server running at http://127.0.0.1:8000/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment