diff --git a/app.js b/app.js index 6aa9355e1..44423e819 100755 --- a/app.js +++ b/app.js @@ -24,24 +24,22 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -// load external and internal libraries (will load more internal binaries later) +// Initialise options and properties. Don't load any handlers here; they +// may need an initialised properties library. var nopt = require('nopt'), os = require('os'), props = require('./lib/properties'), - CompileHandler = require('./lib/compile-handler').CompileHandler, - express = require('express'), child_process = require('child_process'), path = require('path'), fs = require('fs-extra'), http = require('http'), https = require('https'), url = require('url'), - utils = require('./lib/utils'), Promise = require('promise'), - aws = require('./lib/aws'), _ = require('underscore-node'), - logger = require('./lib/logger').logger, - asm_doc_api = require('./lib/asm-docs-api'); + utils = require('./lib/utils'), + express = require('express'), + logger = require('./lib/logger').logger; // Parse arguments from command line 'node ./app.js args...' var opts = nopt({ @@ -89,6 +87,11 @@ if (opts.propDebug) props.setDebug(true); // *All* files in config dir are parsed props.initialize(rootDir + '/config', propHierarchy); +// Now load up our libraries. +var CompileHandler = require('./lib/compile-handler').CompileHandler, + aws = require('./lib/aws'), + asm_doc_api = require('./lib/asm-docs-api'); + // Instantiate a function to access records concerning "compiler-explorer" // in hidden object props.properties var gccProps = props.propsFor("compiler-explorer"); diff --git a/etc/config/asm-docs.amazon.properties b/etc/config/asm-docs.amazon.properties new file mode 100644 index 000000000..53524973b --- /dev/null +++ b/etc/config/asm-docs.amazon.properties @@ -0,0 +1 @@ +staticMaxAgeSecs=3600 diff --git a/etc/config/asm-docs.defaults.properties b/etc/config/asm-docs.defaults.properties new file mode 100644 index 000000000..e90b56d0f --- /dev/null +++ b/etc/config/asm-docs.defaults.properties @@ -0,0 +1 @@ +staticMaxAgeSecs=10 diff --git a/lib/asm-docs-api.js b/lib/asm-docs-api.js index bccfdb287..deaf4c773 100644 --- a/lib/asm-docs-api.js +++ b/lib/asm-docs-api.js @@ -24,8 +24,12 @@ // POSSIBILITY OF SUCH DAMAGE. var asm_doc = require('./asm-docs'); +var props = require('./properties'); -function docHandler(req, res) { +var asmProps = props.propsFor("asm-docs"); +var staticMaxAgeSecs = asmProps('staticMaxAgeSecs', 10); + +function docHandler(req, res, next) { var info = asm_doc.getAsmOpcode(req.params.opcode); if (!info) { // If the opcode ends with an AT&T suffix, try removing that and giving it another go. @@ -36,6 +40,12 @@ function docHandler(req, res) { info = asm_doc.getAsmOpcode(suffixRemoved[1]); } } + if (staticMaxAgeSecs) { + res.setHeader('Cache-Control', 'public, max-age=' + staticMaxAgeSecs); + } + if (!info) { + return res.status(404).send("Unknown opcode"); + } if (req.accepts(['text', 'json']) == 'json') { res.set('Content-Type', 'application/json'); res.end(JSON.stringify(info));