Sha256: b98416dda26cd72c6efc1b6ea70b7b54a3d783c83b332d3d86c33d133b02b807

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

/**
 * Module dependencies.
 */

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

// $ curl http://localhost:3000/

// custom format string

connect.createServer(
    connect.logger(':method :url - :res[content-type]')
  , function(req, res){
    res.statusCode = 500;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Internal Server Error');
  }
).listen(3000);

// $ curl http://localhost:3001/
// $ curl http://localhost:3001/302
// $ curl http://localhost:3001/404
// $ curl http://localhost:3001/500

connect()
  .use(connect.logger('dev'))
  .use('/connect', connect.static(__dirname + '/lib'))
  .use('/connect', connect.directory(__dirname + '/lib'))
  .use(function(req, res, next){
    switch (req.url) {
      case '/500':
        var body = 'Internal Server Error';
        res.statusCode = 500;
        res.setHeader('Content-Length', body.length);
        res.end(body);
        break;
      case '/404':
        var body = 'Not Found';
        res.statusCode = 404;
        res.setHeader('Content-Length', body.length);
        res.end(body);
        break;
      case '/302':
        var body = 'Found';
        res.statusCode = 302;
        res.setHeader('Content-Length', body.length);
        res.end(body);
        break;
      default:
        var body = 'OK';
        res.setHeader('Content-Length', body.length);
        res.end(body);
    }
  })
  .listen(3001);

// pre-defined

connect()
  .use(connect.logger('short'))
  .listen(3002);

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/examples/logger.format.js