Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
feat(vcl): Add extensions.vcl
Browse files Browse the repository at this point in the history
  • Loading branch information
kptdobe committed May 14, 2019
1 parent ad2aa43 commit ae1b52c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function main(params) {
params.service,
params.token,
params.version,
params.vcl,
);

return result;
Expand Down
15 changes: 15 additions & 0 deletions layouts/fastly/extensions.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright 2018 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#

sub hlx_type_pipeline_before {}

sub hlx_type_pipeline_after {}
8 changes: 7 additions & 1 deletion layouts/fastly/helix.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ sub hlx_type_image {
* Handles requests for the main Helix rendering pipeline.
*/
sub hlx_type_pipeline {
call hlx_type_pipeline_before;

set req.http.X-Trace = req.http.X-Trace + "; hlx_type_pipeline";
# This is a dynamic request.

Expand Down Expand Up @@ -787,7 +789,8 @@ sub hlx_type_pipeline {
set req.http.X-Backend-URL = req.http.X-Backend-URL
+ "&params=" + req.http.X-Encoded-Params;
}


call hlx_type_pipeline_after;
}

/**
Expand Down Expand Up @@ -893,6 +896,9 @@ sub vcl_recv {
# re-enable shielding for changed backends
# include "reset.vcl";

# VCL extension points
include "extensions.vcl";

# We only handle GET and HEAD requests, but Proxy strains might
if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") {
error 405;
Expand Down
7 changes: 7 additions & 0 deletions src/fastly/vcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ async function init(fastly, version) {
return fastly.setMainVCL(version, 'helix.vcl');
}

async function extensions(fastly, version) {
const vclfile = path.resolve(__dirname, '../../layouts/fastly/extensions.vcl');
const content = include(vclfile);
return writevcl(fastly, version, content, 'extensions.vcl');
}

function updatestrains(fastly, version, strains) {
return Promise.all([
writevcl(fastly, version, resolve(strains), 'strains.vcl'),
Expand All @@ -37,4 +43,5 @@ function updatestrains(fastly, version, strains) {
module.exports = {
init,
updatestrains,
extensions,
};
1 change: 1 addition & 0 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function publish(configuration, service, token, version) {
backends.init(fastly, version),
backends.updatestrains(fastly, version, config.strains),
vcl.init(fastly, version),
vcl.extensions(fastly, version),
vcl.updatestrains(fastly, version, config.strains),
redirects.updatestrains(fastly, version, config.strains),
dictionaries.init(
Expand Down
12 changes: 11 additions & 1 deletion test/vcl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const assert = require('assert');
const sinon = require('sinon');
const path = require('path');
const { HelixConfig } = require('@adobe/helix-shared');
const { init, updatestrains } = require('../src/fastly/vcl');
const { init, updatestrains, extensions } = require('../src/fastly/vcl');

/* eslint-env mocha */

Expand All @@ -30,6 +30,16 @@ describe('Testing vcl.js', () => {
assert.ok(fastly.setMainVCL.calledOnce);
});

it('#extensions', async () => {
const fastly = {
writeVCL: sinon.fake.returns({})
};

assert.ok(await extensions(fastly, 1));
assert.ok(fastly.writeVCL.calledOnce);
assert.ok(fastly.writeVCL.calledWith(1, 'extensions.vcl'));
});

it('#updatestrains/full', async () => {
const fastly = {
writeVCL: sinon.fake(),
Expand Down

0 comments on commit ae1b52c

Please sign in to comment.