connect-device-router
v0.2.0
Published
Connect middleware to route based on X-UA-Device
Downloads
7
Readme
connect-device-router
Connect middleware to route based on X-UA-Device.
Use with varnish-devicedetect or connect-devicedetect to generate X-UA-Device headers.
Querystring overrides require connect.query
or similar.
connect = require 'connect'
deviceDetect = require 'connect-devicedetect'
device = require 'connect-device-router'
desktopApp = connect()
.use( ... )
mobileApp = connect()
.use( ... )
app = connect()
.use(connect.query())
.use(deviceDetect())
.use(device(phone: mobileApp))
.use(desktopApp)
Or use per-route with express:
express = require 'express'
deviceRouter = require 'connect-device-router'
express()
# map devices to handlers with chained middleware:
.get '/foo',
device 'phone', (req, res, next) ->
# ...
device 'desktop', (req, res, next) ->
# ...
(req, res, next) ->
# default
# or an object literal:
.get '/', device
phone: (req, res, next) -> # ...
tablet: (req, res, next) -> # ...
, (req, res, next) -> # default ...
# or mix both styles:
.get '/',
device phone: (req, res, next) ->
# ...
device tablet: (req, res, next) ->
# ...
(req, res, next) ->
# default ...