Here is my code:
module.exports = (app) ->
app.use '/v1', isValid, router
router.post '/users/:id/authentications', (req, res, next) ->
obj = _.pick(req.body, 'provider', 'uid', 'oauth_token',
'oauth_token_secret', 'nickname')
unless _.isEmpty(obj)
_.extend(obj, { user_id: req.params.id })
sqs.sendMessage
MessageBody: JSON.stringify obj
QueueUrl: sqsQueueURLs['authentications']
, (err, data) ->
if err
log err
res.status(422)
res.json({ 'message': 'Unprocessable Entity' })
else
res.status(201)
res.json({ 'status': 'OK' })
isValid = (req, res, next) ->
apiKey = req.headers['api-key']
if not apiKey
res.status(401)
res.json { 'message': 'API Key is missing from request' }
else
next()
When I do a POST to the /users/:id/authentications endpoint, my app is returning a HTTP status code of 404 when I introduced the middleware. I've probably set it up wrong, but can't figure out how to fix it