dox-foundation-demo node_modules/express/node_modules/connect/lib/proto.js

http

declaration
http

    Description

    Module dependencies.

    Source

    var http = require('http')
      , utils = require('./utils')
      , debug = require('debug')('connect:dispatcher');
    
    // prototype
    
    var app = module.exports = {};
    
    // environment
    
    var env = process.env.NODE_ENV || 'development';

    use

    method
    app.use()
    • @param: {String,Function,Server}route,callback or server
    • @param: {Function,Server}callbackor server
    • @return: {Server}for chaining

    Description

    Utilize the given middleware handle to the given route,
    defaulting to /. This "route" is the mount-point for the
    middleware, when given a value other than / the middleware
    is only effective when that segment is present in the request's
    pathname.

    For example if we were to mount a function at /admin, it would
    be invoked on /admin, and /admin/settings, however it would
    not be invoked for /, or /posts.

    Examples:

     var app = connect();
     app.use(connect.favicon());
     app.use(connect.logger());
     app.use(connect.static(__dirname + '/public'));
    

    If we wanted to prefix static files with /public, we could
    "mount" the static() middleware:

     app.use('/public', connect.static(__dirname + '/public'));
    

    This api is chainable, so the following is valid:

     connect()
       .use(connect.favicon())
       .use(connect.logger())
       .use(connect.static(__dirname + '/public'))
       .listen(3000);
    

    Source

    app.use = function(route, fn){
      // default route to '/'
      if ('string' != typeof route) {
        fn = route;
        route = '/';
      }
    
      // wrap sub-apps
      if ('function' == typeof fn.handle) {
        var server = fn;
        fn.route = route;
        fn = function(req, res, next){
          server.handle(req, res, next);
        };
      }
    
      // wrap vanilla http.Servers
      if (fn instanceof http.Server) {
        fn = fn.listeners('request')[0];
      }
    
      // strip trailing slash
      if ('/' == route[route.length - 1]) {
        route = route.slice(0, -1);
      }
    
      // add the middleware
      debug('use %s %s', route || '/', fn.name || 'anonymous');
      this.stack.push({ route: route, handle: fn });
    
      return this;
    };

    listen

    method
    app.listen()
    • @return: {http.Server}

    Description

    Listen for connections.

    This method takes the same arguments
    as node's http.Server#listen().

    HTTP and HTTPS:

    If you run your application both as HTTP
    and HTTPS you may wrap them individually,
    since your Connect "server" is really just
    a JavaScript Function.

     var connect = require('connect')
       , http = require('http')
       , https = require('https');
    
     var app = connect();
    
     http.createServer(app).listen(80);
     https.createServer(options, app).listen(443);
    

    Source

    app.listen = function(){
      var server = http.createServer(this);
      return server.listen.apply(server, arguments);
    };