Have ideas to improve npm?Join in the discussion! »

connect-device-routerTypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

connect-device-router NPM version Build Status

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 ... 
 

Keywords

none

Install

npm i connect-device-router

DownloadsWeekly Downloads

5

Version

0.2.0

License

none

Last publish

Collaborators

  • avatar
  • avatar