How to use express-useragent - 10 common examples

To help you get started, we’ve selected a few express-useragent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / server / boot / index.js View on Github external
function setup() {
	const app = express();

	// for nginx
	app.enable( 'trust proxy' );

	app.use( cookieParser() );
	app.use( userAgent.express() );

	if ( 'development' === process.env.NODE_ENV ) {
		require( 'bundler' )( app );

		// setup logger
		app.use( morgan( 'dev' ) );

		if ( config.isEnabled( 'wpcom-user-bootstrap' ) ) {
			if ( config( 'wordpress_logged_in_cookie' ) ) {
				const username = config( 'wordpress_logged_in_cookie' ).split( '%7C' )[ 0 ];
				console.info( chalk.cyan( '\nYour logged in cookie set to user: ' + username ) );

				app.use( function( req, res, next ) {
					if ( ! req.cookies.wordpress_logged_in ) {
						req.cookies.wordpress_logged_in = config( 'wordpress_logged_in_cookie' );
					}
github GitbookIO / nuts / lib / nuts.js View on Github external
// Secret for GitHub webhook
        refreshSecret: 'secret'
    });

    // .init() is now a memoized version of ._init()
    this.init = _.memoize(this._init);

    // Create router
    this.router = express.Router();

    // Create backend
    this.backend = new (BACKENDS(this.opts.backend))(this, this.opts);
    this.versions = new Versions(this.backend);

    // Bind routes
    this.router.use(useragent.express());

    this.router.get('/', this.onDownload);
    this.router.get('/download/channel/:channel/:platform?', this.onDownload);
    this.router.get('/download/version/:tag/:platform?', this.onDownload);
    this.router.get('/download/:tag/:filename', this.onDownload);
    this.router.get('/download/:platform?', this.onDownload);

    this.router.get('/feed/channel/:channel.atom', this.onServeVersionsFeed);

    this.router.get('/update', this.onUpdateRedirect);
    this.router.get('/update/:platform/:version', this.onUpdate);
    this.router.get('/update/channel/:channel/:platform/:version', this.onUpdate);
    this.router.get('/update/:platform/:version/RELEASES', this.onUpdateWin);
    this.router.get('/update/channel/:channel/:platform/:version/RELEASES', this.onUpdateWin);

    this.router.get('/notes/:version?', this.onServeNotes);
github imbhargav5 / dictionary-offline / server / index.production.js View on Github external
import config from '../app/config/index';
/**
 * Gzip compression module
 */
import compress from 'compression';
var useragent = require('express-useragent');

let app = express();
// Redirect all HTTP traffic to HTTPS
function ensureSecure(req, res, next){
   // handle port numbers if you need non defaults
};


app.use(compress());
app.use(useragent.express());
app.use(express.static('static'));
app.use((req,res,next)=>{
if(req.useragent.browser==='Chrome' && parseInt(req.useragent.version)>43){
if(req.secure){
     console.log(req.useragent.browser, req.useragent.version, parseInt(req.useragent.version)); 
     console.log("Secure within chrome ");
     // OK, continue
    return next();
  }
 else{
  console.log("insecure within chrome "+req.hostname,req.url);
  console.log("redirecting");
 res.redirect('https://'+req.hostname+req.url);
 }
}else{
  console.log('not chrome, hence next()');
github juicycleff / ultimate-backend / libs / common / src / setup / auth.setup.ts View on Github external
export function authSetup(app: INestApplication) {
  app.use(sessionMiddleware);
  app.use(passportMiddleware);
  app.use(passportSessionMiddleware);
  app.use(cookieParser());
  app.use(useragent.express());

  // @ts-ignore
  app.set('subdomain offset', 1); // Enable sub domain in app
}
github mayeaux / nodetube / app.js View on Github external
next();
      } else {
        lusca.csrf()(req, res, next);
      }
    });

    app.use(lusca.xframe('SAMEORIGIN'));
    app.use(lusca.xssProtection(true));

    // pass user to frontend
    app.use((req, res, next) => {
      res.locals.user = req.user;
      next();
    });

    app.use(useragent.express());


    // TODO: where is this being used?
    app.use((req, res, next) => {
      if (process.env.NODE_ENV == 'production') {
        res.locals.linkPrepend = 'https://pew.tube';
      } else {
        res.locals.linkPrepend = '';
      }
      next();
    });

    // not being used currently
    function nocache(req, res, next) {
      res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
      res.header('Expires', '-1');
github imperiojs / imperio / index.js View on Github external
return (req, res, next) => {
      // Create an object on the req object that we can store stuff in
      req.imperio = {};
      req.imperio.connected = false;
      req.imperio.roomCookieTimeout = that.roomCookieTimeout;
      // Bind our middleware dependencies, then finally our middleware function
      const boundImperioMiddleware = imperioMiddleware
            .bind(null, req, res, next);
      const boundCookieParserMiddleware = cookieParser()
            .bind(null, req, res, boundImperioMiddleware);
      const boundBodyParserJsonMiddleware = bodyParser.json()
            .bind(null, req, res, boundCookieParserMiddleware);
      const boundBodyParserUrlMiddleware = bodyParser.urlencoded({ extended: true })
            .bind(null, req, res, boundBodyParserJsonMiddleware);
      const boundUserAgentMiddleware = useragent.express()
            .bind(null, req, res, boundBodyParserUrlMiddleware);

      // Execute the bound chain of middleware
      boundUserAgentMiddleware();
    };
  };
github imperiojs / imperio / index.js View on Github external
return (req, res, next) => {
      // Create an object on the req object that we can store stuff in
      req.imperio = {};
      req.imperio.connected = false;
      req.imperio.roomCookieTimeout = that.roomCookieTimeout;
      // Bind our middleware dependencies, then finally our middleware function
      const boundImperioMiddleware = imperioMiddleware
            .bind(null, req, res, next);
      const boundCookieParserMiddleware = cookieParser()
            .bind(null, req, res, boundImperioMiddleware);
      const boundBodyParserJsonMiddleware = bodyParser.json()
            .bind(null, req, res, boundCookieParserMiddleware);
      const boundBodyParserUrlMiddleware = bodyParser.urlencoded({ extended: true })
            .bind(null, req, res, boundBodyParserJsonMiddleware);
      const boundUserAgentMiddleware = useragent.express()
            .bind(null, req, res, boundBodyParserUrlMiddleware);

      // Execute the bound chain of middleware
      boundUserAgentMiddleware();
    };
  };
github jinroh / kadoh / apps / bench / app / controller.js View on Github external
var express = require('express'),
    uagent  = require('express-useragent'),
    _       = require('underscore');

var Result = app.settings.db.import(__dirname+'/models/result.js');

app.use(express.bodyParser())
   .use(uagent.express());

app.get('/', function(req, res) {
  res.render('index');
});

app.get('/monitor', function(req, res) {
  res.render('monitor');
});

app.post('/results', function(req, res) {
  var infos = {
    user_agent : [req.useragent.Browser, req.useragent.OS].join(','),
    mobile     : req.useragent.isMobile,
    dht_size   : app.settings.dht.size
  };
github juicycleff / ultimate-backend / apps / gateway-client / src / main.ts View on Github external
app.use(enableMultiTenancy({
    enabled: true,
    tenantResolver: {
      resolverType: 'Header',
      headerKeys: {
        tenant: 'x-tenant-id',
        key: 'x-tenant-key',
        secret: 'x-tenant-secret',
      },
      requiresToken: true,
    },
    databaseStrategy: TenantDatabaseStrategy.DataIsolation,
  }));
  AppUtils.killAppWithGrace(app);
  app.use(cookieParser());
  app.use(useragent.express());

  await app.listenAsync(
    parseInt(process.env.PORT, 10) ||
    parseInt(config.gateway?.client?.port, 10) ||
    5000,
  );
}
bootstrap();
github uuchat / uuchat / src / index.js View on Github external
{ stream: {
                    write: message => logger.info(message.trim())
                }
            }
    ));

    app.use('/static/images', express.static(path.join(__dirname, './client/static/images')));
    app.use('/content/upload', express.static(path.join(__dirname, '../content/upload')));
    app.use('/content/avatar', express.static(path.join(__dirname, '../content/avatar')));
    app.use('/public', express.static(path.join(__dirname, '../content/html')));

    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended: false}));
    app.use(cookieParser(nconf.get('socket.io:secretKey')));

    app.use(useragent.express());
    setupFavicon(app);
    if (global.env === 'development') {
        var webpack = require('webpack');
        var webpackMiddleware = require('webpack-dev-middleware');
        var webpackHotMiddleware = require('webpack-hot-middleware');
        var config = require('../tools/webpack.config.dev.js');
        var compiler = webpack(config);
        var middlewareDev = webpackMiddleware(compiler, {
            publicPath: config.output.publicPath,
            contentBase: 'src',
            stats: {
                colors: true,
                hash: false,
                timings: true,
                chunks: false,
                chunkModules: false,

express-useragent

ExpressJS/Connect/TrinteJS user-agent middleware exposing

MIT
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis

Popular express-useragent functions