Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
467f9a53b2 |
|
@ -15,12 +15,23 @@ var DocumentHandler = function(options) {
|
|||
DocumentHandler.defaultKeyLength = 10;
|
||||
|
||||
// Handle retrieving a document
|
||||
DocumentHandler.prototype.handleGet = function(key, response, skipExpire) {
|
||||
DocumentHandler.prototype.handleGet = function(key, callback, response, skipExpire) {
|
||||
this.store.get(key, function(ret) {
|
||||
if (ret) {
|
||||
winston.verbose('retrieved document', { key: key });
|
||||
response.writeHead(200, { 'content-type': 'application/json' });
|
||||
response.end(JSON.stringify({ data: ret, key: key }));
|
||||
var responseData = JSON.stringify({ data: ret, key: key });
|
||||
if (callback) {
|
||||
if (callback.match(/^[a-z0-9]+$/i)) {
|
||||
response.writeHead(200, { 'content-type': 'application/javascript' });
|
||||
response.end(callback + '(' + responseData + ');');
|
||||
} else {
|
||||
response.writeHead(400, { 'content-type': 'application/json' });
|
||||
response.end(JSON.stringify({ message: 'invalid callback function name' }));
|
||||
}
|
||||
} else {
|
||||
response.writeHead(200, { 'content-type': 'application/json' });
|
||||
response.end(responseData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
winston.warn('document not found', { key: key });
|
||||
|
|
|
@ -116,8 +116,10 @@ connect.createServer(
|
|||
// get documents
|
||||
app.get('/documents/:id', function(request, response, next) {
|
||||
var skipExpire = !!config.documents[request.params.id];
|
||||
var parsedUrl = url.parse(request.url, true);
|
||||
return documentHandler.handleGet(
|
||||
request.params.id,
|
||||
parsedUrl.query.callback,
|
||||
response,
|
||||
skipExpire
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user