Skip to content

Commit

Permalink
Throw 404s!
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierumbelow committed Apr 28, 2012
1 parent 4cf7749 commit d9b8013
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -20,4 +20,6 @@ Change the bound hostname and port with the `-l` and `-p` flags, respectively:

## HTTP API

The HTTP API will open up on the next port from the Postmaster port. Sending an `HTTP GET` request to `/emails` will return a JSON array of the parsed email and associated headers.
The HTTP API will open up on the next port from the Postmaster port. Sending an `HTTP GET` request to `/emails` will return a JSON array of the parsed email and associated headers.

$ curl http://localhost:5667/emails
13 changes: 11 additions & 2 deletions lib/api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/api.coffee
Expand Up @@ -8,5 +8,9 @@ class exports.API
next() if next?

handle: (req, res) ->
res.writeHead(200)
res.end 'Hello World!'
if req.url is '/ping'
res.writeHead 200, { 'Content-Type': 'text/html' }
res.end '<a href="https://github.com/jamierumbelow/postmaster">Postmaster</a> reporting for duty'
else
res.writeHead 404, { 'Content-Type': 'text/html' }
res.end '<h1>404 Not Found</h1>'
14 changes: 10 additions & 4 deletions test/api_test.coffee
Expand Up @@ -10,9 +10,15 @@ module.exports = testCase
testServerIsCreated: (test) ->
test.ok (@api.server instanceof http.Server), '@api.server isn\'t an instance of http.Server'

getRequest 'localhost', 5667, '/', (data) =>
test.equal data, 'Hello World!'
test.ok(true)
getRequest 'localhost', 5667, '/ping', (data) =>
test.equal data, '<a href="https://github.com/jamierumbelow/postmaster">Postmaster</a> reporting for duty'

test.done()

testServerThrows404: (test) ->
getRequest 'localhost', 5667, '/jkljfoiwuro8aw8fw498', (data, res) =>
test.equal data, '<h1>404 Not Found</h1>'
test.equal res.statusCode, 404

test.done()

Expand All @@ -23,4 +29,4 @@ module.exports = testCase
getRequest = (host, port, path, next) ->
http.get { host: host, port: port, path: path}, (res) ->
res.on 'data', (data) ->
next data.toString()
next data.toString(), res

0 comments on commit d9b8013

Please sign in to comment.