1.0.0 • Published 7 years ago

voorhees v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Voorhees

Express middleware to determine if JSON should assault your client.

Huh?

Voorhees is an express middleware module that will call the response object's json or render functions, depending on if the request object's xhr property is either true (will call json()) or false (will call render())

Usage

Voorhees can be applied as middleware for your entire app

let express = require('express')
let app = express()
let voorhees = require('voorhees')

app.use(voorhees)

Or can be applied to a specific route

let express = require('express')
let router = require('express').Router
let voorhees = require('voorhees')

router.use(voorhees)

In either case, voorhees applies itself as a propertyvoorhees on the response object. This can then be accessed by your route handling code and calling the respond() function:

router.get('/', function (req, res){
  res.voorhees.respond('view/path', {'yourData': foo})
})

Now, your response will either be JSON (if request was called via ajax), or will render your view as HTML.

1.0.0

7 years ago