How to use connect - 10 common examples

To help you get started, we’ve selected a few connect 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 Bahmni / openmrs-module-bahmniapps / node_modules / testacular / node_modules / http-proxy / examples / node_modules / connect-jsonp / examples / example.js View on Github external
// note: assumes the connect & connect-json node packages are installed 
var connect = require('connect'),
    jsonp   = require('../lib/connect-jsonp');

var response = {
  success: true,
  it: 'works!'    
};

var server = connect.createServer(
  connect.logger({ format: ':method :url' }),
  connect.bodyParser(),
  jsonp(),
  connect.router(app),
  connect.errorHandler({ dumpExceptions: true, showStack: true })

).listen(3000);

console.log('connect-jsonp example server listening on port 3000');

function app(app) {
  // simple alert, not exactly x-domain...
  app.get('/', function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('');
  });
github node-webot / wechat / test / list.test2.js View on Github external
require('should');
var List = require('../').List;

var request = require('supertest');
var template = require('./support').template;
var tail = require('./support').tail;

var connect = require('connect');
var wechat = require('../');

var app = connect();
app.use(connect.query());
app.use(connect.cookieParser());
app.use(connect.session({secret: 'keyboard cat', cookie: {maxAge: 60000}}));
app.use('/wechat', wechat('some token', function (req, res, next) {
  // 微信输入信息都在req.weixin上
  var info = req.weixin;
  if (info.Content === 'list') {
    res.wait('view');
  }
}));

describe('list', function() {
  it('should ok with list', function (done) {
    List.add('view', [
      ['回复{c}查看我的性取向', '这样的事情怎么好意思告诉你啦- -']
    ]);
    var info = {
      sp: 'test',
github ciaranj / connect-auth / examples / connect-testing.js View on Github external
res.end('hello world - un-authenticated');
      }
   });   
}

// Demonstrates janrain when embedded in link
function janrain(req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'})
  if( req.isAuthenticated() )  {
    res.end("Signed in :  " + req.session.auth.user.email);
  }
  else {
    res.end("<a href="https://express-auth.rpxnow.com/openid/v2/signin?foo=bar&amp;token_url=http%3A%2F%2Flocalhost%2Fauth%2Fjanrain_callback"> Sign In </a>");
  }
}
var server= connect.createServer( connect.cookieDecoder(), 
                      connect.session({ store: new MemoryStore({ reapInterval: -1 }) }),
                      connect.bodyDecoder() /* Only required for the janrain strategy*/,
                      auth({"basic": new StrategyDefinition(Basic,{getPasswordForUser: getPasswordForUserFunction}),
                                     "github": new StrategyDefinition(Github, {appId : ghId, appSecret: ghSecret, callback: ghCallbackAddress}),
                                     "digest": new StrategyDefinition(Digest,{getPasswordForUser: getPasswordForUserFunction}),
                                     "yahoo": new StrategyDefinition(Yahoo, {consumerKey: yahooConsumerKey, consumerSecret: yahooConsumerSecret, callback: yahooCallbackAddress}),
                                     "facebook": new StrategyDefinition(Facebook, {appId : fbId, appSecret: fbSecret, scope: "email", callback: fbCallbackAddress}),
                                     "twitter": new StrategyDefinition(Twitter, {consumerKey: twitterConsumerKey, consumerSecret: twitterConsumerSecret}),
                                     "http": new StrategyDefinition(Http, {getPasswordForUser: getPasswordForUserFunction}),
                                     "janrain": new StrategyDefinition(Janrain, {apiKey: janrainApiKey, 
                                                                                 appDomain: janrainAppDomain, 
                                                                                 callback: janrainCallbackUrl}),
                                     "anon": new StrategyDefinition(Anonymous),
                                     "never": new StrategyDefinition(Never)}), 
                       /*helloWorld*/
                      janrain);
github derbyjs / racer / test / session / http.js View on Github external
// From TJ's connect test/support/http

/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter
  , methods = ['get', 'post', 'put', 'delete', 'head']
  , connect = require('connect')
  , http = require('http');

module.exports = request;

connect.proto.request = function(server){
  return request(this, server);
};

function request(app, server) {
  return new Request(app, server);
}

function Request(app, server) {
  var self = this;
  this.data = [];
  this.header = {};
  this.app = app;
  this.server = server;
  if (!this.server) {
    this.server = http.Server(app);
    this.server.listen(0, function(){
github webcast-io / jobukyu / index.js View on Github external
} catch (e) {
  console.error('Unable to open config module/file ' + configPath);
  process.exit(1);
}


// App
//
var app = connect();



// Use the logger if environment config allows
//
if (config.log) {
  app.use(connect.logger('dev'));
}



// Append connect middleware
//
app.use(connect.query());
app.use(connect.json());



// Defines support for res.json in controller
// actions
//
// @req   {Object}    The http request object
// @res   {Object}    The http response object
github node-modules / weibo / examples / connect_with_oauth_middleware.js View on Github external
var weibo = require('../');

/**
 * init weibo api settings
 */ 

weibo.init('weibo', '1122960051', 'e678e06f627ffe0e60e2ba48abe3a1e3');
// weibo.init('github', '8e14edfda73a71f1f226', '1796ac639a8ada0dff6acfee2d63390440ca0f3b');
weibo.init('tqq', '801196838', '9f1a88caa8709de7dccbe3cae4bdc962');

/**
 * Create a web application.
 */

var app = connect(
  connect.query(),
  connect.cookieParser('oh year a cookie secret'),
  connect.session({ secret: "oh year a secret" }),
  // using weibo.oauth middleware for use login
  // will auto save user in req.session.oauthUser
  weibo.oauth({
    loginPath: '/login',
    logoutPath: '/logout',
    callbackPath: '/oauth/callback',
    blogtypeField: 'type',
    afterLogin: function (req, res, callback) {
      console.log(req.session.oauthUser.screen_name, 'login success');
      process.nextTick(callback);
    },
    beforeLogout: function (req, res, callback) {
      console.log(req.session.oauthUser.screen_name, 'loging out');
      process.nextTick(callback);
github mklabs / backnode / examples / wiki / app.js View on Github external
} else if(method === "update") {
    // impl
  } else if(method === "delete") {
    // impl
  }
};



  
  
connect.createServer()
  .use(connect.logger(':method :url :status :res[content-length] - :response-time ms'))
  .use(Backnode(new Router))
  .use(connect.directory(__dirname))
  .use(connect.static(__dirname))
  .use(function(req, res, next){return next(new Backnode.UrlError('Foobar'))})
  .use(Backnode.errorHandler({ stack: true }))
  .listen(4000);

console.log('Server started, up and running on port 4000');
github bnoguchi / everyauth / index.js View on Github external
var path = require('path');
var EventEmitter = require('events').EventEmitter;
var connect = require('connect');
var express = require('express');
var ExpressRouter = require('express/lib/router');
var __pause = connect.utils.pause;
var merge = require('./lib/utils').merge;

var everyauth = module.exports = {};


everyauth.helpExpress = function () {
  console.warn('everyauth.helpExpress is being deprecated. helpExpress is now automatically invoked when it detects express. So remove everyauth.helpExpress from your code');
  return this;
};

everyauth.debug = false;

// The connect middleware. e.g.,
//     connect(
//         ...
//       , everyauth.middleware()
github mklabs / h5bp-docs / lib / h5bp.js View on Github external
server = function server(config) {
  // but only for configuration with config.server set to true (--server)
  if(!config.server) return;
  connect.createServer()
    .use(connect.logger({format: '> :date :method :url'}))
    .use(connect.favicon(Path.join(__dirname, '../public/favicon.ico')))
    .use(config.baseurl || '', connect.static(Path.join(config.dest)))
    .listen(config.port);

  console.log('\nServer started: localhost:', config.port);
},
github kn0ll / backbone-osc / server.js View on Github external
var Connect = require('connect'),
    Jade = require('jade'),
    Socket = require('socket.io-connect').socketIO,
    Fs = require('fs'),
    _ = require('./static/webroot/js/lib/underscore'),
    osc = require('./lib/node-osc/lib/osc'),
    jspack = require('./lib/node-osc/lib/node-jspack/jspack').jspack;
    
    
var server = Connect.createServer(
    
    Socket(function() { return server }, function (client, req, res) {
        
        var osc_send = new osc.Client(8000, '127.0.0.1');
        
        // listen from client on port 8000
        // to create osc signal
        client.on('message', function(data) {
            
            var args = data.split('/'),
                val = args.pop();
            osc_send.sendSimple(args.join('/'), [parseFloat(val)]);
           
        });
        
    }),