mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-05-18 00:32:33 -04: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 async = require('async');
|
||||||
var defaults = require('lodash.defaults');
|
var defaults = require('lodash.defaults');
|
||||||
var fastlyConfig = require('./lib/fastly-config-methods');
|
var fastlyConfig = require('./lib/fastly-config-methods');
|
||||||
|
const languages = require('./languages.json');
|
||||||
|
|
||||||
var route_json = require('../src/routes.json');
|
var route_json = require('../src/routes.json');
|
||||||
|
|
||||||
|
@ -46,18 +47,42 @@ async.auto({
|
||||||
var passStatement = fastlyConfig.negateConditionStatement(notPassStatement);
|
var passStatement = fastlyConfig.negateConditionStatement(notPassStatement);
|
||||||
|
|
||||||
// For a non-pass condition, point backend at s3
|
// For a non-pass condition, point backend at s3
|
||||||
var backendCondition = fastlyConfig.setBackend(
|
var recvCondition = '' +
|
||||||
'F_s3',
|
'if (' + notPassStatement + ') {\n' +
|
||||||
S3_BUCKET_NAME,
|
' set req.backend = F_s3;\n' +
|
||||||
notPassStatement
|
' set req.http.host = \"' + S3_BUCKET_NAME + '\";\n' +
|
||||||
);
|
'} else {\n' +
|
||||||
// For a pass condition, set forwarding headers
|
' if (!req.http.Fastly-FF) {\n' +
|
||||||
var forwardCondition = fastlyConfig.setForwardHeaders(passStatement);
|
' 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(
|
fastly.setCustomVCL(
|
||||||
results.version,
|
results.version,
|
||||||
'recv-condition',
|
'recv-condition',
|
||||||
backendCondition + forwardCondition,
|
recvCondition,
|
||||||
cb
|
cb
|
||||||
);
|
);
|
||||||
}],
|
}],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue