Permalink
Browse files

Remove all unused code and update share to use send

  • Loading branch information...
1 parent a9919fd commit 1e8fa036b9c75d5422d6ffd9cc84d63fb134fa0f @creationix committed Oct 25, 2013
Showing with 30 additions and 591 deletions.
  1. +0 −53 auth.js
  2. +0 −101 autoloader.js
  3. +0 −32 autoloader/bootstrap.js
  4. +0 −23 deleter.js
  5. +0 −9 index.js
  6. +0 −82 indexer.js
  7. +0 −32 log.js
  8. +8 −6 package.json
  9. +0 −36 postReceive.js
  10. +0 −27 route.js
  11. +22 −18 share.js
  12. +0 −87 static.js
  13. +0 −46 substack.js
  14. +0 −22 uploader.js
  15. +0 −17 vhost.js
View
@@ -1,53 +0,0 @@
-// Based loosly on basicAuth from Connect
-// Checker takes username and password and returns a user if valid
-// Will force redirect if requested over HTTP instead of HTTPS
-module.exports = function basicAuth(checker, realm) {
-
- realm = realm || 'Authorization Required';
-
- function unauthorized(res) {
- res.writeHead(401, {
- 'WWW-Authenticate': 'Basic realm="' + realm + '"',
- 'Content-Length': 12
- });
- res.end("Unauthorized");
- }
-
- function badRequest(res) {
- res.writeHead(400, {
- "Content-Length": 11
- });
- res.end('Bad Request');
- }
-
- return function(req, res, next) {
- // Check for non SSL connections
- if (!req.socket.encrypted) {
- var parts = req.headers.host.split(":");
- var host = parts[0];
- var port = parseInt(parts[1], 10);
- if (port !== 80) {
- port = port - (port % 1000) + 443;
- host = host + ":" + port;
- }
- var url = "https://" + host + req.realUrl;
- res.writeHead(301, {
- Location: url,
- "Content-Length": 0
- });
- res.end();
- return;
- }
- var authorization = req.headers.authorization;
- if (!authorization) return unauthorized(res);
- var parts = authorization.split(' ');
- var scheme = parts[0];
- var credentials = new Buffer(parts[1], 'base64').toString().split(':');
- if ('Basic' != scheme) return badRequest(res);
- var user = checker(req, credentials[0], credentials[1]);
- if (!user) return unauthorized(res);
- req.remoteUser = user;
- next();
- }
-};
-
View
@@ -1,101 +0,0 @@
-// TODO: Put in some sort of lock so that the same dep won't get loaded
-// multiple times in parallel.
-// TODO: Use etag or last-modified and/or keep stuff in memory for improved
-// performance.
-// The user will need to npm install ugilify-js on their own to use that option.
-
-var Fs = require('fs'),
- Path = require('path'),
- Url = require('url'),
- QueryString = require('querystring');
-
-var findAll = new RegExp("require\\(['\"][^\"']+['\"]\\)", "g");
-var findName = new RegExp("require\\(['\"]([^\"']+)['\"]\\)");
-
-module.exports = function setup(mount, folder, uglify) {
-
- if (uglify) {
- var jsp = require("uglify-js").parser;
- var pro = require("uglify-js").uglify;
- }
-
- return function handle(req, res, next) {
- if (!req.uri) { req.uri = Url.parse(req.url); }
- if (req.uri.pathname !== mount) return next();
- var names = req.uri.query.split(",").reverse();
-
- var has = {};
- var scripts = [];
- var header;
-
- function loadScript(name, callback) {
- if (!name) throw new Error("must provide name");
- if (has.hasOwnProperty(name)) return process.nextTick(callback);
- var path = Path.join(folder, name + ".js");
- Fs.readFile(path, 'utf8', function (err, js) {
- if (err) return callback(err);
- var matches = js.match(findAll);
-
- if (matches) {
- matches = Array.prototype.slice.call(matches).map(function (dep) {
- return dep.match(findName)[1];
- }).reverse();
-
- function getDep(err) {
- if (err) return next(err);
- var dep = matches.pop();
- if (!dep) return doneDeps();
- loadScript(dep, getDep);
- }
- getDep();
-
- } else {
- doneDeps();
- }
- function doneDeps() {
- if (!has[name]) { // Make sure only one version is in the generated JS
- has[name] = true;
- scripts.push([name, js]);
- }
- callback();
- }
-
- });
- }
-
- function getName(err) {
- if (err) return next(err);
- var name = names.pop();
- if (!name) return done();
- loadScript(name, getName);
- }
- Fs.readFile(__dirname + "/autoloader/bootstrap.js", 'utf8', function (err, js) {
- if (err) return next(err);
- header = js;
- getName();
- });
-
- function done(err) {
- var js = header;
- scripts.forEach(function (tuple) {
- var name = tuple[0];
- var content = tuple[1];
- js += "\ndefine('" + name + "', function (module, exports) {\n\n" + content + "\n})\n";
- });
-
- if (uglify) {
- var ast = jsp.parse(js); // parse code and get the initial AST
- ast = pro.ast_mangle(ast); // get a new AST with mangled names
- ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
- js = pro.gen_code(ast); // compressed code here
- }
-
- res.writeHead(200, {
- "Content-Type": "application/javascript",
- "Content-Length": Buffer.byteLength(js)
- });
- res.end(js);
- }
- };
-};
-
@@ -1,32 +0,0 @@
-// Super simple require system to go along with the server-side help in the
-// autoloader middleware for "creationix".
-(function () {
-
-// Store our repository in private variables in this closure.
-var defs = {},
- modules = {};
-
-// When the user defines a module's setup function, store it here.
-function define(name, fn) {
- defs[name] = fn;
-}
-
-// The first time a module is used, it's description is executed and cached.
-function require(name) {
- if (modules.hasOwnProperty(name)) return modules[name];
- if (defs.hasOwnProperty(name)) {
- var exports = modules[name] = {};
- var module = {exports:exports};
- var fn = defs[name];
- fn(module, exports);
- return modules[name] = module.exports;
- }
- throw new Error("Module not found: " + name);
-}
-
-// Expose our public API on the global object.
-this.define = define;
-this.require = require;
-
-}());
-
View
@@ -1,23 +0,0 @@
-var Url = require('url');
-var FS = require('fs');
-var Path = require('path');
-
-module.exports = function deleter(mount, root) {
- return function (req, res, next) {
- if (req.method !== "DELETE") return next();
- if (!req.uri) { req.uri = Url.parse(req.url); }
- var path = unescape(req.uri.pathname).replace(/\.\.+/g, '.');
- if (!path || path.substr(0, mount.length) !== mount) {
- return next();
- }
- path = Path.join(root, path.substr(mount.length));
- FS.unlink(path, function (err) {
- if (err) {
- if (err.code == "ENOENT") return next();
- return next(err);
- }
- res.writeHead(200, {});
- res.end();
- });
- };
-}
View
@@ -1,9 +0,0 @@
-require('fs').readdirSync(__dirname).forEach(function (name) {
- if (name !== 'index.js' && name.substr(name.length-3) === ".js") {
- var name = name.substr(0, name.length - 3);
- Object.defineProperty(exports, name, {get: function () {
- return require("./" + name);
- }, enumerable: true});
- }
-});
-
View
@@ -1,82 +0,0 @@
-var Fs = require('fs'),
- Path = require('path'),
- Url = require('url'),
- getMime = require('simple-mime')("application/octet-stream");
-
-module.exports = function setup(mount, root, showHidden) {
-
- return function handle(req, res, next) {
- if (!req.uri) { req.uri = Url.parse(req.url); }
- var path = unescape(req.uri.pathname).replace(/\.\.+/g, '.');
- if (!path || path.substr(0, mount.length) !== mount) {
- return next();
- }
- path = Path.join(root, path.substr(mount.length));
- if (path[path.length - 1] === '/') { path = path.substr(0, path.length - 1); }
- Fs.stat(path, function (err, stat) {
- if (err) {
- if (err.code === 'ENOENT') { return next(); }
- return next(err);
- }
- if (!stat.isDirectory()) {
- return next();
- }
- Fs.readdir(path, function (err, files) {
- if (err) { return next(err); }
- if (path !== root) {
- files.unshift('..');
- }
-
- var data = new Array(files.length);
- var left = files.length;
- files.sort();
- files.forEach(function (file, index) {
- var fullPath = Path.join(path, file);
- var item = data[index] = {
- name: file
- };
- Fs.stat(fullPath, function (err, stat) {
- if (err) { return checkQueue(); }
- item.stat = stat;
- if (stat.isDirectory()) {
- item.isDirectory = true;
- item.name += "/";
- } else {
- item.mime = getMime(file);
- }
- checkQueue();
- });
- });
- function checkQueue() {
- left--;
- if (left > 0) { return; }
- var html = data.map(function (item) {
- return '<li' + (item.name[0] === '.' && item.name !== '..' ? ' class="hidden" ' : '') + '><a href="' + h(item.name) + '">' + h(item.name) + '</a></li>';
- }).join("\n");
- html = '<h1>' + h(path) + '</h1>\n' +
- '<ul>' + html + '</ul>';
- if (!showHidden) {
- html = '<style>.hidden{display:none;}</style>\n' + html;
- }
- res.writeHead(200, {
- "Content-Type": "text/html",
- "Content-Length": Buffer.byteLength(html)
- });
- res.end(html);
- }
- });
- });
- };
-};
-
-function renderIndex(root, files, callback) {
- getData(root, files, function (err, data) {
- });
-}
-
-
-function h(text) {
- return text.replace(/&/g, '&amp;').
- replace(/>/g, '&gt;').
- replace(/</g, '&lt;');
-}
View
@@ -1,32 +0,0 @@
-// A super simple logging middleware
-module.exports = function setup(special) {
- special = special || {
- "Content-Type": true,
- "Location": true,
- "Content-Length": true,
- "Content-Range": true,
- };
- return function handle(req, res, next) {
- var writeHead = res.writeHead;
- var start = Date.now();
- res.writeHead = function (code, headers) {
- var extra = [];
- if (headers) {
- Object.keys(headers).forEach(function (key) {
- if (special.hasOwnProperty(key)) {
- extra.push(key + "=" + headers[key]);
- }
- });
- if (!headers.hasOwnProperty('Date')) {
- headers.Date = (new Date()).toUTCString();
- }
- headers.Server = "NodeJS " + process.version;
- headers["X-Runtime"] = Date.now() - start;
- }
- console.log("%s %s %s %s", req.method, req.url, code, extra.join(" "));
- res.writeHead = writeHead;
- res.writeHead(code, headers);
- };
- next();
- };
-};
View
@@ -1,17 +1,19 @@
{
"name": "creationix",
"description": "Creationix is a meta package for my personal packages",
- "tags": ["stack", "creationix", "meta", "sandbox"],
- "version": "0.3.1",
+ "tags": [
+ "creationix"
+ ],
+ "version": "0.4.0",
"author": "Tim Caswell <tim@creationix.com>",
"repository": {
"type": "git",
"url": "http://github.com/creationix/creationix.git"
},
- "main": "index.js",
- "bin": { "share": "./share.js" },
+ "bin": {
+ "share": "./share.js"
+ },
"dependencies": {
- "stack": ">=0.0.3",
- "simple-mime": ">=0.0.1"
+ "send": "~0.1.4"
}
}
Oops, something went wrong.

0 comments on commit 1e8fa03

Please sign in to comment.