Skip to content

Commit

Permalink
fix(construct.awscdk.cloudfront-url-rewrite): disable eslint no-var f…
Browse files Browse the repository at this point in the history
…or cloudfront js v1 compatibility

Signed-off-by: Braden Mars <[email protected]>
  • Loading branch information
BradenM committed Jul 4, 2024
1 parent bfac6a2 commit 7350ca1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* eslint-disable no-var */
import type { CloudFrontFunctionsEvent } from 'aws-lambda'

const FROM_HOSTNAME = '<FROM_HOSTNAME>'
const REDIRECT_URI_PATTERN = new RegExp('<REDIRECT_URI_PATTERN>', 'g')
const TO_HOSTNAME = '<TO_HOSTNAME>'
const TARGET_URI_PATTERN = '<TARGET_URI_PATTERN>'
var FROM_HOSTNAME = '<FROM_HOSTNAME>'
var REDIRECT_URI_PATTERN = new RegExp('<REDIRECT_URI_PATTERN>', 'g')
var TO_HOSTNAME = '<TO_HOSTNAME>'
var TARGET_URI_PATTERN = '<TARGET_URI_PATTERN>'

/**
* cloudfront-js supports a limited subset of javascript/ecma features.
*/
// eslint-disable-next-line @typescript-eslint/require-await,@typescript-eslint/no-unused-vars
function handler(event: CloudFrontFunctionsEvent) {
const request = event.request
const headers = request.headers
const uri = request.uri
var request = event.request
var headers = request.headers
var uri = request.uri

const hostParams = headers.host
let host = ''
var hostParams = headers.host
var host = ''
if (hostParams && hostParams.value) {
host = hostParams.value
}
Expand All @@ -24,8 +25,8 @@ function handler(event: CloudFrontFunctionsEvent) {
return request
}

const newUri = uri.replace(REDIRECT_URI_PATTERN, TARGET_URI_PATTERN)
const newUrl = `https://${TO_HOSTNAME}${newUri}`
var newUri = uri.replace(REDIRECT_URI_PATTERN, TARGET_URI_PATTERN)
var newUrl = `https://${TO_HOSTNAME}${newUri}`
return {
statusCode: 301,
statusDescription: 'Moved Permanently',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7350ca1

Please sign in to comment.