Loading TODO.md +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ * Proper markdown highlighting * Better about page text * test new interface in browsers * compress assets * cache static assets in memory with connect * look for a better way to do router # shared version only Loading config.js +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ "maxLength": 400000, "cacheStaticAssets": false, "staticMaxAge": 86400, "logging": [ { Loading package.json +2 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,8 @@ "dependencies": { "winston": "*", "hashlib": "*" "hashlib": "*", "connect": "*" }, "devDependencies": { Loading server.js +27 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ var url = require('url'); var fs = require('fs'); var winston = require('winston'); var connect = require('connect'); var StaticHandler = require('./lib/static_handler'); var DocumentHandler = require('./lib/document_handler'); // Load the configuration and set some defaults Loading Loading @@ -52,9 +52,6 @@ for (var name in config.documents) { }); } // 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, Loading @@ -62,21 +59,31 @@ var documentHandler = new DocumentHandler({ 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') { // Set the server up with a static cache connect.createServer( connect.router(function(app) { // add documents app.post('/documents', function(request, response, next) { return documentHandler.handlePost(request, response); } // Looking up a doc var match = incoming.pathname.match(/^\/documents\/([A-Za-z0-9]+)$/); if (request.method == 'GET' && match) { return documentHandler.handleGet(match[1], response); } // Otherwise, look for static file staticHandler.handle(incoming.pathname, response); }).listen(config.port, config.host); }); // get documents app.get('/documents/:id', function(request, response, next) { return documentHandler.handleGet(req.params.id, response); }); }), // Otherwise, static connect.staticCache(), connect.static(__dirname + '/static', { maxAge: config.staticMaxAge }), // Then we can loop back - and change these into '/' TODO connect.router(function(app) { app.get('/:id', function(request, response, next) { request.url = request.originalUrl = '/'; next(); }); }), // Static connect.staticCache(), connect.static(__dirname + '/static', { maxAge: config.staticMaxAge }) ).listen(config.port, config.host); winston.info('listening on ' + config.host + ':' + config.port); Loading
TODO.md +3 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ * Proper markdown highlighting * Better about page text * test new interface in browsers * compress assets * cache static assets in memory with connect * look for a better way to do router # shared version only Loading
config.js +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ "maxLength": 400000, "cacheStaticAssets": false, "staticMaxAge": 86400, "logging": [ { Loading
package.json +2 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,8 @@ "dependencies": { "winston": "*", "hashlib": "*" "hashlib": "*", "connect": "*" }, "devDependencies": { Loading
server.js +27 −20 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ var url = require('url'); var fs = require('fs'); var winston = require('winston'); var connect = require('connect'); var StaticHandler = require('./lib/static_handler'); var DocumentHandler = require('./lib/document_handler'); // Load the configuration and set some defaults Loading Loading @@ -52,9 +52,6 @@ for (var name in config.documents) { }); } // 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, Loading @@ -62,21 +59,31 @@ var documentHandler = new DocumentHandler({ 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') { // Set the server up with a static cache connect.createServer( connect.router(function(app) { // add documents app.post('/documents', function(request, response, next) { return documentHandler.handlePost(request, response); } // Looking up a doc var match = incoming.pathname.match(/^\/documents\/([A-Za-z0-9]+)$/); if (request.method == 'GET' && match) { return documentHandler.handleGet(match[1], response); } // Otherwise, look for static file staticHandler.handle(incoming.pathname, response); }).listen(config.port, config.host); }); // get documents app.get('/documents/:id', function(request, response, next) { return documentHandler.handleGet(req.params.id, response); }); }), // Otherwise, static connect.staticCache(), connect.static(__dirname + '/static', { maxAge: config.staticMaxAge }), // Then we can loop back - and change these into '/' TODO connect.router(function(app) { app.get('/:id', function(request, response, next) { request.url = request.originalUrl = '/'; next(); }); }), // Static connect.staticCache(), connect.static(__dirname + '/static', { maxAge: config.staticMaxAge }) ).listen(config.port, config.host); winston.info('listening on ' + config.host + ':' + config.port);