mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-16 16:19:48 -05:00
Simplify how the conditional is created for setting the S3 backend, caching related behavior for non-logged in users and maintaining language settings and passing to backend
This commit is contained in:
parent
7a6be0306b
commit
279e25eb69
1 changed files with 33 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
var async = require('async');
|
||||
var defaults = require('lodash.defaults');
|
||||
var fastlyConfig = require('./lib/fastly-config-methods');
|
||||
const languages = require('./languages.json');
|
||||
|
||||
var route_json = require('../src/routes.json');
|
||||
|
||||
|
@ -46,18 +47,42 @@ async.auto({
|
|||
var passStatement = fastlyConfig.negateConditionStatement(notPassStatement);
|
||||
|
||||
// For a non-pass condition, point backend at s3
|
||||
var backendCondition = fastlyConfig.setBackend(
|
||||
'F_s3',
|
||||
S3_BUCKET_NAME,
|
||||
notPassStatement
|
||||
);
|
||||
// For a pass condition, set forwarding headers
|
||||
var forwardCondition = fastlyConfig.setForwardHeaders(passStatement);
|
||||
var recvCondition = '' +
|
||||
'if (' + notPassStatement + ') {\n' +
|
||||
' set req.backend = F_s3;\n' +
|
||||
' set req.http.host = \"' + S3_BUCKET_NAME + '\";\n' +
|
||||
'} else {\n' +
|
||||
' if (!req.http.Fastly-FF) {\n' +
|
||||
' if (req.http.X-Forwarded-For) {\n' +
|
||||
' set req.http.Fastly-Temp-XFF = req.http.X-Forwarded-For \", \" client.ip;\n' +
|
||||
' } else {\n' +
|
||||
' set req.http.Fastly-Temp-XFF = client.ip;\n' +
|
||||
' }\n' +
|
||||
' } else {\n' +
|
||||
' set req.http.Fastly-Temp-XFF = req.http.X-Forwarded-For;\n' +
|
||||
' }\n' +
|
||||
' set req.grace = 60s;\n' +
|
||||
' if (req.http.Cookie:scratchlanguage) {\n' +
|
||||
' set req.http.Accept-Language = req.http.Cookie:scratchlanguage;\n' +
|
||||
' } else {\n' +
|
||||
' set req.http.Accept-Language = accept.language_lookup("' +
|
||||
Object.keys(languages).join(':') + '", ' +
|
||||
'"en", ' +
|
||||
'std.tolower(req.http.Accept-Language)' +
|
||||
');\n' +
|
||||
' }\n' +
|
||||
' if (req.url ~ "^/projects/" && !req.http.Cookie:scratchsessionid) {\n' +
|
||||
' set req.http.Cookie = req.http.Cookie:scratchlanguage;\n' +
|
||||
' } else {\n' +
|
||||
' return(pass);\n' +
|
||||
' }\n' +
|
||||
'}\n';
|
||||
|
||||
|
||||
fastly.setCustomVCL(
|
||||
results.version,
|
||||
'recv-condition',
|
||||
backendCondition + forwardCondition,
|
||||
recvCondition,
|
||||
cb
|
||||
);
|
||||
}],
|
||||
|
|
Loading…
Reference in a new issue