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..d67ef6f 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["originName"]; +const viewerName1 = process.env["viewerName"]; +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..6f78aa1 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", "") // 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", ""); // 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..0e00767 100644 --- a/serverless.yml +++ b/serverless.yml @@ -15,12 +15,12 @@ provider: role: LambdaEdgeRole # you can overwrite defaults here -# stage: dev + stage: ${env:stage} # you can define service wide environment variables here -# environment: -# variable1: value1 - + environment: + viewerName: dev + originName: dev # you can add packaging information here #package: # include: @@ -31,7 +31,7 @@ provider: # - exclude-me-dir/** functions: - viewerRequest: + viewerRequest: handler: handler.viewerRequest timeout: 5 originRequest: @@ -57,7 +57,7 @@ resources: Policies: - PolicyName: LambdaEdgeExecutionRole PolicyDocument: - Version: "2012-10-17" +# Version: "2012-10-17" Statement: - Effect: Allow Action: