Loading TODO +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ cache headers for static assets (and on document GET) tests add feedback for errors to UI - esp. too long add about page fix that chrome bug where it loads the doc twice add link to about page # shared version only some way to do announcements easily (and use for ads) Loading about.md 0 → 100644 +5 −0 Original line number Diff line number Diff line # Haste Sharing code is a good thing, and it should be _really_ easy to do it. A lot of times, I want to show you something I'm seeing - and that's where we use pastebins. Haste is the prettiest, easist to use pastebin every made. config.js +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ "port": 6379, "db": 2, "expire": 3600 }, "documents": { "about": "./about.md" } } lib/redis_document_store.js +4 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,16 @@ RedisDocumentStore.connect = function(options) { }; // Save file in a key RedisDocumentStore.prototype.set = function(key, data, callback) { RedisDocumentStore.prototype.set = function(key, data, callback, skipExpire) { var _this = this; RedisDocumentStore.client.set(key, data, function(err, reply) { if (err) { callback(false); } else { if (!skipExpire) { _this.setExpiration(key); } callback(true); } }); Loading server.js +24 −10 Original line number Diff line number Diff line Loading @@ -37,29 +37,43 @@ if (!config.storage.type) { var Store = require('./lib/' + config.storage.type + '_document_store'); var preferredStore = new Store(config.storage); // Send the static documents into the preferred store, skipping expirations for (var name in config.documents) { var path = config.documents[name]; fs.readFile(path, 'utf8', function(err, data) { if (data && !err) { preferredStore.set(name, data, function(cb) { winston.info('loaded static document', { name: name, path: path }); }, true); } else { winston.warn('failed to load static document', { name: name, path: path }); } }); } // Configure a static handler for the static files var staticHandler = new StaticHandler('./static', !!config.cacheStaticAssets); // Configure the document handler var documentHandler = new DocumentHandler({ store: preferredStore, maxLength: config.maxLength, keyLength: config.keyLength }); // Set the server up and listen forever http.createServer(function(request, response) { var incoming = url.parse(request.url, false); var handler = null; // Looking to add a new doc if (incoming.pathname.match(/^\/documents$/) && request.method == 'POST') { handler = new DocumentHandler({ keyLength: config.keyLength, maxLength: config.maxLength, store: preferredStore }); return handler.handlePost(request, response); return documentHandler.handlePost(request, response); } // Looking up a doc var match = incoming.pathname.match(/^\/documents\/([A-Za-z0-9]+)$/); if (request.method == 'GET' && match) { handler = new DocumentHandler({ store: preferredStore }); return handler.handleGet(match[1], response); return documentHandler.handleGet(match[1], response); } // Otherwise, look for static file staticHandler.handle(incoming.pathname, response); Loading Loading
TODO +2 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ cache headers for static assets (and on document GET) tests add feedback for errors to UI - esp. too long add about page fix that chrome bug where it loads the doc twice add link to about page # shared version only some way to do announcements easily (and use for ads) Loading
about.md 0 → 100644 +5 −0 Original line number Diff line number Diff line # Haste Sharing code is a good thing, and it should be _really_ easy to do it. A lot of times, I want to show you something I'm seeing - and that's where we use pastebins. Haste is the prettiest, easist to use pastebin every made.
config.js +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ "port": 6379, "db": 2, "expire": 3600 }, "documents": { "about": "./about.md" } }
lib/redis_document_store.js +4 −2 Original line number Diff line number Diff line Loading @@ -34,14 +34,16 @@ RedisDocumentStore.connect = function(options) { }; // Save file in a key RedisDocumentStore.prototype.set = function(key, data, callback) { RedisDocumentStore.prototype.set = function(key, data, callback, skipExpire) { var _this = this; RedisDocumentStore.client.set(key, data, function(err, reply) { if (err) { callback(false); } else { if (!skipExpire) { _this.setExpiration(key); } callback(true); } }); Loading
server.js +24 −10 Original line number Diff line number Diff line Loading @@ -37,29 +37,43 @@ if (!config.storage.type) { var Store = require('./lib/' + config.storage.type + '_document_store'); var preferredStore = new Store(config.storage); // Send the static documents into the preferred store, skipping expirations for (var name in config.documents) { var path = config.documents[name]; fs.readFile(path, 'utf8', function(err, data) { if (data && !err) { preferredStore.set(name, data, function(cb) { winston.info('loaded static document', { name: name, path: path }); }, true); } else { winston.warn('failed to load static document', { name: name, path: path }); } }); } // Configure a static handler for the static files var staticHandler = new StaticHandler('./static', !!config.cacheStaticAssets); // Configure the document handler var documentHandler = new DocumentHandler({ store: preferredStore, maxLength: config.maxLength, keyLength: config.keyLength }); // Set the server up and listen forever http.createServer(function(request, response) { var incoming = url.parse(request.url, false); var handler = null; // Looking to add a new doc if (incoming.pathname.match(/^\/documents$/) && request.method == 'POST') { handler = new DocumentHandler({ keyLength: config.keyLength, maxLength: config.maxLength, store: preferredStore }); return handler.handlePost(request, response); return documentHandler.handlePost(request, response); } // Looking up a doc var match = incoming.pathname.match(/^\/documents\/([A-Za-z0-9]+)$/); if (request.method == 'GET' && match) { handler = new DocumentHandler({ store: preferredStore }); return handler.handleGet(match[1], response); return documentHandler.handleGet(match[1], response); } // Otherwise, look for static file staticHandler.handle(incoming.pathname, response); Loading