Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env stages #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules
jspm_packages

# Serverless directories
.serverless
.serverless

replacements.txt
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ invalidate:
CLOUDFRONT_DISTRIBUTION_ID="${CLOUDFRONT_DISTRIBUTION_ID}" node create-invalidation.js

listinvalidations:
aws cloudfront list-invalidations --distribution-id "" | head
aws cloudfront list-invalidations --distribution-id "${CLOUDFRONT_DISTRIBUTION_ID}" | tail | head -25

test:
DEBUG=prerendercloud PRERENDER_SERVICE_URL="https://service.prerender.cloud" ./node_modules/jasmine/bin/jasmine.js
14 changes: 12 additions & 2 deletions deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ if (!process.env["CLOUDFRONT_DISTRIBUTION_ID"]) {

CLOUDFRONT_DISTRIBUTION_ID = process.env["CLOUDFRONT_DISTRIBUTION_ID"];

const viewjoin = 'Lambda-Edge-Prerendercloud-' + process.env["color"] + '-viewerRequest';
const originjoin = 'Lambda-Edge-Prerendercloud-' + process.env["color"] + '-originRequest';
const originName1 = process.env["stage"];
const viewerName1 = process.env["stage"];
const viewer = viewjoin //+ ':' + viewerName1;
const origin = originjoin //+ ':' + originName1;
console.log(viewer);
console.log(origin);

const lambdaMappings = [
{
FunctionName: "Lambda-Edge-Prerendercloud-dev-viewerRequest",
FunctionName: viewer,
EventType: "viewer-request"
},
{
FunctionName: "Lambda-Edge-Prerendercloud-dev-originRequest",
FunctionName: origin,
EventType: "origin-request"
}
];
console.log(lambdaMappings);

const AWS = require("aws-sdk");
AWS.config.region = "us-east-1";
Expand Down
4 changes: 2 additions & 2 deletions handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const resetPrerenderCloud = () => {
// 1. prerenderToken (API token, you'll be rate limited without it)
// Get it after signing up at https://www.prerender.cloud/
// note: Lambda@Edge doesn't support env vars, so hardcoding is your only option.
// prerendercloud.set("prerenderToken", "mySecretToken")
prerendercloud.set("prerenderToken", "mySecretToken")

// 2. protocol (optional, default is https)
// use this to force a certain protocol for requests from service.prerender.cloud to your origin
Expand All @@ -35,7 +35,7 @@ const resetPrerenderCloud = () => {
// set it, the only info we'd have access to during Lambda@Edge runtime is the host of the origin (S3)
// which would require additional configuration to make it publicly accessible (and it just makes things more confusing).
// example value: example.com or d1pxreml448ujs.cloudfront.net (don't include the protocol)
// prerendercloud.set("host", "");
prerendercloud.set("host", "<${color}.test.com DNS Example CNAME>");

// 4. removeTrailingSlash (recommended)
// Removes trailing slash from URLs to increase prerender.cloud server cache hit rate
Expand Down
13 changes: 7 additions & 6 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ provider:
role: LambdaEdgeRole

# you can overwrite defaults here
# stage: dev
stage: ${env:stage}
color: ${env:color}

# you can define service wide environment variables here
# you can not define service wide environment variables here as Lambda won't accept them
# environment:
# variable1: value1

# viewerName: dev
# originName: dev
# you can add packaging information here
#package:
# include:
Expand All @@ -31,7 +32,7 @@ provider:
# - exclude-me-dir/**

functions:
viewerRequest:
viewerRequest:
handler: handler.viewerRequest
timeout: 5
originRequest:
Expand All @@ -57,7 +58,7 @@ resources:
Policies:
- PolicyName: LambdaEdgeExecutionRole
PolicyDocument:
Version: "2012-10-17"
# Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
Expand Down
2 changes: 1 addition & 1 deletion spec/viewerRequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe("viewerRequest", function() {

// since shouldPrerender is false, it rewrites uri for cache-key
describe("curl user-agent", function() {
withUserAgentAndUri("curl", "/nexted/path");
withUserAgentAndUri("curl", "/nested/path");
runHandlerWithViewerRequestEvent();

itDoesNotPrerender("curl", "/index.html");
Expand Down