'use strict';
var app = function (options) {
  var express     = require('express'),
      app         = express(),
      logger      = require('./logger')(options.silent),
      Controllers = require('./controllers'),
      controllers = new Controllers(options.directory, logger, options.indexDocument, options.errorDocument),
      concat      = require('concat-stream'),
      path        = require('path');

  /**
   * Log all requests
   */
  app.use(require('morgan')('tiny', {
    'stream': {
      write: function (message) {
        logger.info(message.slice(0, -1));
      }
    }
  }));

  app.use(function (req, res, next) {
    req.pipe(concat(function (data) {
      req.body = data;
      next();
    }));
  });

  app.use(function (req, res, next) {
    var host = req.headers.host.split(':')[0];

    if (options.indexDocument && host !== 'localhost' && host !== '127.0.0.1') {
      req.url = path.join('/', host, req.url);
    }

    next();
  });

  app.disable('x-powered-by');

  /**
   * Routes for the application
   */
  app.get('/', controllers.getBuckets);
  app.get('/:bucket', controllers.bucketExists, controllers.getBucket);
  app.delete('/:bucket', controllers.bucketExists, controllers.deleteBucket);
  app.put('/:bucket', controllers.putBucket);
  app.put('/:bucket/:key(*)', controllers.bucketExists, controllers.putObject);
  app.get('/:bucket/:key(*)', controllers.bucketExists, controllers.getObject);
  app.head('/:bucket/:key(*)', controllers.getObject);
  app.delete('/:bucket/:key(*)', controllers.bucketExists, controllers.deleteObject);

  return {
    serve: function (done) {
      return app.listen(options.port, options.hostname, function (err) {
        return done(err, options.hostname, options.port, options.directory);
      }).on('error', function (err) {
        return done(err);
      });
    }
  };
};

module.exports = app;

@@ -943,16 +943,327 @@
 %0A    %7D%0A%0A
+    if (req.method === 'OPTIONS') %7B%0A      if (req.headers%5B'access-control-request-method'%5D)%0A        res.header('Access-Control-Allow-Origin', '*');%0A      if (req.headers%5B'access-control-request-headers'%5D)%0A        res.header('Access-Control-Allow-Headers', req.headers%5B'access-control-request-headers'%5D);%0A    %7D%0A%0A
     next

Support CORS requests