Skip to content

Commit

Permalink
Added the ability to retrieve raw documents
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
seejohnrun committed Dec 16, 2011
1 parent 8add491 commit 44f7ab3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/document_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ DocumentHandler.prototype.handleGet = function(key, response, skipExpire) {
}, skipExpire);
};

// Handle retrieving the raw version of a document
DocumentHandler.prototype.handleRawGet = function(key, response, skipExpire) {
this.store.get(key, function(ret) {
if (ret) {
winston.verbose('retrieved raw document', { key: key });
response.writeHead(200, { 'content-type': 'text/plain' });
response.end(ret);
}
else {
winston.warn('raw document not found', { key: key });
response.writeHead(404, { 'content-type': 'application/json' });
response.end(JSON.stringify({ message: 'document not found' }));
}
}, skipExpire);
};

// Handle adding a new Document
DocumentHandler.prototype.handlePost = function(request, response) {
var _this = this;
Expand Down
6 changes: 6 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ var documentHandler = new DocumentHandler({
connect.createServer(
// First look for api calls
connect.router(function(app) {
// get raw documents - support getting with extension
app.get('/raw/:id', function(request, response, next) {
var skipExpire = !!config.documents[request.params.id];
var key = request.params.id.split('.')[0];
return documentHandler.handleRawGet(key, response, skipExpire);
});
// add documents
app.post('/documents', function(request, response, next) {
return documentHandler.handlePost(request, response);
Expand Down

0 comments on commit 44f7ab3

Please sign in to comment.