Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
fd6211bc
Unverified
Commit
fd6211bc
authored
Dec 01, 2017
by
Colby Gutierrez-Kraybill
Committed by
GitHub
Dec 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1712 from LLK/hotfix/project-caching
[Master] Hotfix/project caching
parents
4ab0b73d
c65b0ef9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
88 deletions
+51
-88
bin/configure-fastly.js
bin/configure-fastly.js
+33
-12
bin/lib/fastly-config-methods.js
bin/lib/fastly-config-methods.js
+9
-42
test/unit/test_fastly_config_methods.js
test/unit/test_fastly_config_methods.js
+9
-34
No files found.
bin/configure-fastly.js
View file @
fd6211bc
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
'
);
...
@@ -41,23 +42,43 @@ async.auto({
...
@@ -41,23 +42,43 @@ async.auto({
// on any of those route conditions.
// on any of those route conditions.
var
notPassStatement
=
fastlyConfig
.
getAppRouteCondition
(
'
../build/*
'
,
routes
,
extraAppRoutes
,
__dirname
);
var
notPassStatement
=
fastlyConfig
.
getAppRouteCondition
(
'
../build/*
'
,
routes
,
extraAppRoutes
,
__dirname
);
// For all the routes in routes.json, construct a varnish-style regex that matches
// only if NONE of those routes are matched.
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:scratchsessionsid) {
\n
'
+
'
set req.http.Cookie = "scratchlanguage=" 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
+
forward
Condition
,
recv
Condition
,
cb
cb
);
);
}],
}],
...
...
bin/lib/fastly-config-methods.js
View file @
fd6211bc
...
@@ -84,45 +84,6 @@ var FastlyConfigMethods = {
...
@@ -84,45 +84,6 @@ var FastlyConfigMethods = {
return
'
redirects/
'
+
route
.
pattern
;
return
'
redirects/
'
+
route
.
pattern
;
},
},
/**
* Returns custom vcl configuration as a string for setting the backend
* of a request to the given backend/host.
*
* @param {string} backend name of the backend declared in fastly
* @param {string} host name of the s3 bucket to be set as the host
* @param {string} condition condition under which backend should be set
*/
setBackend
:
function
(
backend
,
host
,
condition
)
{
return
''
+
'
if (
'
+
condition
+
'
) {
\n
'
+
'
set req.backend =
'
+
backend
+
'
;
\n
'
+
'
set req.http.host =
\
"
'
+
host
+
'
\
";
\n
'
+
'
}
\n
'
;
},
/**
* Returns custom vcl configuration as a string for headers that
* should be added for the condition in which a request is forwarded.
*
* @param {string} condition condition under which to set pass headers
*/
setForwardHeaders
:
function
(
condition
)
{
return
''
+
'
if (
'
+
condition
+
'
) {
\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
'
+
'
return(pass);
\n
'
+
'
}
\n
'
;
},
/**
/**
* Returns custom vcl configuration as a string that sets the varnish
* Returns custom vcl configuration as a string that sets the varnish
* Time to Live (TTL) for responses that come from s3.
* Time to Live (TTL) for responses that come from s3.
...
@@ -132,9 +93,15 @@ var FastlyConfigMethods = {
...
@@ -132,9 +93,15 @@ var FastlyConfigMethods = {
setResponseTTL
:
function
(
condition
)
{
setResponseTTL
:
function
(
condition
)
{
return
''
+
return
''
+
'
if (
'
+
condition
+
'
) {
\n
'
+
'
if (
'
+
condition
+
'
) {
\n
'
+
'
if (req.url ~ "^/projects/" && !req.http.Cookie:scratchsessionsid) {
\n
'
+
'
set beresp.http.Vary = "Accept-Encoding, Accept-Language";
\n
'
+
'
unset beresp.http.set-cookie;
\n
'
+
'
return(deliver);
\n
'
+
'
} else {
\n
'
+
'
set beresp.ttl = 0s;
\n
'
+
'
set beresp.ttl = 0s;
\n
'
+
'
set beresp.grace = 0s;
\n
'
+
'
set beresp.grace = 0s;
\n
'
+
'
return(pass);
\n
'
+
'
return(pass);
\n
'
+
'
}
\n
'
+
'
}
\n
'
;
'
}
\n
'
;
}
}
};
};
...
...
test/unit/test_fastly_config_methods.js
View file @
fd6211bc
...
@@ -59,44 +59,19 @@ tap.test('getAppRouteCondition', function (t) {
...
@@ -59,44 +59,19 @@ tap.test('getAppRouteCondition', function (t) {
t
.
end
();
t
.
end
();
});
});
tap
.
test
(
'
testSetBackend
'
,
function
(
t
)
{
var
backend
=
fastlyConfig
.
setBackend
(
'
wemust
'
,
'
goback
'
,
'
marty
'
);
t
.
equal
(
backend
,
''
+
'
if (marty) {
\n
'
+
'
set req.backend = wemust;
\n
'
+
'
set req.http.host =
\
"goback
\
";
\n
'
+
'
}
\n
'
);
t
.
end
();
});
tap
.
test
(
'
testSetForward
'
,
function
(
t
)
{
var
forward
=
fastlyConfig
.
setForwardHeaders
(
'
alwaysforward
'
);
t
.
equal
(
forward
,
''
+
'
if (alwaysforward) {
\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
'
+
'
return(pass);
\n
'
+
'
}
\n
'
);
t
.
end
();
});
tap
.
test
(
'
testSetTTL
'
,
function
(
t
)
{
tap
.
test
(
'
testSetTTL
'
,
function
(
t
)
{
var
ttl
=
fastlyConfig
.
setResponseTTL
(
'
itsactuallyttyl
'
);
var
ttl
=
fastlyConfig
.
setResponseTTL
(
'
itsactuallyttyl
'
);
t
.
equal
(
ttl
,
''
+
t
.
equal
(
ttl
,
''
+
'
if (itsactuallyttyl) {
\n
'
+
'
if (itsactuallyttyl) {
\n
'
+
'
if (req.url ~ "^/projects/" && !req.http.Cookie:scratchsessionsid) {
\n
'
+
'
set beresp.http.Vary = "Accept-Encoding, Accept-Language";
\n
'
+
'
unset beresp.http.set-cookie;
\n
'
+
'
return(deliver);
\n
'
+
'
} else {
\n
'
+
'
set beresp.ttl = 0s;
\n
'
+
'
set beresp.ttl = 0s;
\n
'
+
'
set beresp.grace = 0s;
\n
'
+
'
set beresp.grace = 0s;
\n
'
+
'
return(pass);
\n
'
+
'
return(pass);
\n
'
+
'
}
\n
'
+
'
}
\n
'
'
}
\n
'
);
);
t
.
end
();
t
.
end
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment