From a541630848adc8d1a4a746de51769f2f3fa780bc Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 17 Jul 2019 16:38:13 +0530 Subject: [PATCH] Add /:id/raw --- server.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 57bd3da..5f598a8 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,4 @@ +// vim: set ts=2 sw=2 sts=2 et: var http = require('http'); var fs = require('fs'); @@ -106,14 +107,17 @@ if (config.rateLimits) { app.use(connect_rate_limit(config.rateLimits)); } +function raw(request, response) { + var key = request.params.id.split('.')[0]; + var skipExpire = !!config.documents[key]; + return documentHandler.handleRawGet(key, response, skipExpire); +} + // first look at API calls app.use(route(function(router) { // get raw documents - support getting with extension - router.get('/raw/:id', function(request, response) { - var key = request.params.id.split('.')[0]; - var skipExpire = !!config.documents[key]; - return documentHandler.handleRawGet(key, response, skipExpire); - }); + router.get('/raw/:id', raw); + router.get('/:id/raw', raw); // add documents router.post('/documents', function(request, response) { return documentHandler.handlePost(request, response); @@ -137,7 +141,7 @@ app.use(connect_st({ // Then we can loop back - and everything else should be a token, // so route it back to / app.use(route(function(router) { - router.get('/:id', function(request, response, next) { + router.get('/:id', function(request, _response, next) { request.sturl = '/'; next(); });