diff --git a/.gitignore b/.gitignore index 2b48c8b..6450435 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ node_modules jspm_packages # Serverless directories -.serverless \ No newline at end of file +.serverless + +replacements.txt diff --git a/Makefile b/Makefile index 796049c..479e15b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/deploy.js b/deploy.js index 2ca09a9..5221cb9 100644 --- a/deploy.js +++ b/deploy.js @@ -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"; diff --git a/handler.js b/handler.js index 0b5fdc7..438c93c 100644 --- a/handler.js +++ b/handler.js @@ -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 @@ -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 diff --git a/serverless.yml b/serverless.yml index 7881aca..3179c07 100644 --- a/serverless.yml +++ b/serverless.yml @@ -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: @@ -31,7 +32,7 @@ provider: # - exclude-me-dir/** functions: - viewerRequest: + viewerRequest: handler: handler.viewerRequest timeout: 5 originRequest: @@ -57,7 +58,7 @@ resources: Policies: - PolicyName: LambdaEdgeExecutionRole PolicyDocument: - Version: "2012-10-17" +# Version: "2012-10-17" Statement: - Effect: Allow Action: diff --git a/spec/viewerRequestSpec.js b/spec/viewerRequestSpec.js index a52998b..1a1ff7b 100644 --- a/spec/viewerRequestSpec.js +++ b/spec/viewerRequestSpec.js @@ -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");