mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Set caching headers on asm API requests
This commit is contained in:
17
app.js
17
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");
|
||||
|
||||
1
etc/config/asm-docs.amazon.properties
Normal file
1
etc/config/asm-docs.amazon.properties
Normal file
@@ -0,0 +1 @@
|
||||
staticMaxAgeSecs=3600
|
||||
1
etc/config/asm-docs.defaults.properties
Normal file
1
etc/config/asm-docs.defaults.properties
Normal file
@@ -0,0 +1 @@
|
||||
staticMaxAgeSecs=10
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user