How to use the connect.createServer function in connect

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 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 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)]);
           
        });
        
    }),
github modjs / mod / lib / tasks / server.js View on Github external
if(options.proxies){
        var proxy  = require('../utils/proxy');
        proxy.config(options.proxies);
        middleware.push(proxy.proxyRequest);
    }

    if(options.console){
        exports.log("remote logging service enable");

        var consolePort = options.consolePort = Number(String(options.console)) || 9999;
        var consoleId = options.consoleId = utils.randomString();

        // start a standalone logging server
        connect.router =  require('../utils/router');
        var consoleServer = connect.createServer(
            connect.bodyParser(),
            connect.static(path.join(__dirname, '../../asset/jsconsole')),
            connect.router( require('../utils/remotelogging') )
        );

        consoleServer.listen(consolePort);
        exports.log('success start remote logging server on port ' + consolePort + '.');

        var url = 'http://127.0.0.1:'+ consolePort + '/?:listen ' + consoleId;
        exports.log('open browser:', url.green);
        utils.open(url);
    }

    // auto reload server
    if(options.reload) {
        middleware.push( connect.static(path.join(__dirname, '../../asset/livereload')) );
github eladb / node-connect-girror / samples / server.js View on Github external
exec('tar -xf foo_repo.tar', function(err) {
    if (err) throw err;

    var app = connect.createServer();
    var secret = '/bhmn489dkjh8m';
    var foo_path = path.join(__dirname, 'foo_repo');
    app.use('/foo', girror(foo_path, { verbose: true, hook: secret }));
    app.use('/goo', girror(foo_path + '#goo', { verbose: true, hook: secret }));
    app.use('/', function(req, res, next) {
        res.write('GET /foo and GET /goo will proxy the request to the app\n');
        res.write('POST /foo' + secret + ' and POST /goo' + secret + ' will redeploy\n');
        return res.end();
    });

    app.listen(5000);
    console.log('listening on 5000');
});
github pylonide / pylon / server / cloud9 / index.js View on Github external
workspaceId: name,
            name: name,
            version: options.version
        };
        var ide = new IdeServer(serverOptions, server, exts);

        return function(req, res, next) {
            if (!req.session.uid)
                req.session.uid = "owner_" + req.sessionID;

            ide.addUser(req.session.uid, User.OWNER_PERMISSIONS);
            ide.handle(req, res, next);
        };
    };

    var server = Connect.createServer();

    server.use(Connect.cookieDecoder());

    var sessionStore = new MemoryStore({ reapInterval: -1 });
    server.use(Connect.session({
        store: sessionStore,
        key: "cloud9.sid"
    }));

    server.use(ideProvider(projectDir, server, sessionStore));
    server.use(middleware.staticProvider(Path.normalize(__dirname + "/../../support"), "/static/support"));
    server.use(middleware.staticProvider(Path.normalize(__dirname + "/../../client"), "/static"));

    //obfuscate process rights if configured
    if (group)
        process.setgid(group);
github creationix / howtonode.org / articles / connect-it / app.js View on Github external
var Connect = require('connect');

module.exports = Connect.createServer(
  require('./log-it')(),
  require('./serve-js')()
);
github AnalogJ / dropstore-ng / server.js View on Github external
var connect = require('connect');
connect.createServer(
    connect.static(__dirname)
).listen(process.env.PORT||8080);
github codice / ddf / search-ui / mapsearch / src / main / webapp / server.js View on Github external
/*global require,__dirname*/
var connect = require('connect');
connect.createServer(
 connect.static(__dirname)
).listen(8083);