Skip to content

Commit

Permalink
support remote images (#44)
Browse files Browse the repository at this point in the history
* support remote images

* fix changelog date

---------

Co-authored-by: Eleftherios Myriounis <[email protected]>
  • Loading branch information
emyriounis and Eleftherios Myriounis authored Dec 4, 2023
1 parent 9c4080a commit fb08e9b
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
<!-- ## [Unreleased] -->


## [v0.2.18] - 2023-12-04

* Support remote images [#44](https://github.com/Nexode-Consulting/terraform-aws-nextjs-serverless/pull/44)


## [v0.2.17] - 2023-11-23

Updates:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Please check our [testing guidelines](https://github.com/Nexode-Consulting/terra
```diff
module "tf_next" {
- source = "Nexode-Consulting/nextjs-serverless/aws"
- version = "0.2.17"
- version = "0.2.18"
+ source = "../../../"
...
}
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs-v13/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs",
"version": "0.2.17",
"version": "0.2.18",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -13,7 +13,7 @@
},
"dependencies": {
"autoprefixer": "^10.4.15",
"build-serverless-next": "^0.2.17",
"build-serverless-next": "^0.2.18",
"next": "^13.4.19",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-v13/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module "next_serverless" {
source = "../../../"
# source = "Nexode-Consulting/nextjs-serverless/aws"
# version = "0.2.17"
# version = "0.2.18"

deployment_name = var.deployment_name
region = var.region
Expand Down
4 changes: 4 additions & 0 deletions examples/nextjs-v13/terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
output "next_serverless" {
value = module.next_serverless
}

output "cloudfront_url" {
value = module.next_serverless.cloudfront_url
}
16 changes: 0 additions & 16 deletions examples/nextjs-v13/terraform/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,3 @@ provider "aws" {
alias = "global_region"
region = var.global_region
}

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.67.0"
}
}

backend "s3" {
bucket = "{{bucket name}}"
key = "{{bucket key}}/terraform.tfstate"
region = "{{bucket region}}"
encrypt = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rm -r standalone
rm -r deployments

# Install necessary packages
npm i -D [email protected] [email protected] [email protected] [email protected] [email protected].17 [email protected].17
npm i -D [email protected] [email protected] [email protected] [email protected] [email protected].18 [email protected].18

# Inject code in build, and cleanup
cp -a ./app ./app-backup
Expand Down
2 changes: 1 addition & 1 deletion packages/build-serverless-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-serverless-next",
"version": "0.2.17",
"version": "0.2.18",
"description": "Bash script to build serverless component for deploying to AWS using Terraform",
"bin": {
"build-serverless-next": "./bin/build-serverless-next.sh"
Expand Down
4 changes: 2 additions & 2 deletions packages/image-redirection/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/image-redirection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-redirection",
"version": "0.2.17",
"version": "0.2.18",
"description": "Image Redirection Lambda",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions packages/image-redirection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ export const handler = async (event: any, _context: any, callback: any) => {
{}
)

// Return original image if it's remote image
if (/^(http|https)%3A%2F%2F/.test(query?.url)) {
/* The URL for the original image. */
const imageUrl = query?.url.replace(/%3A/g, ':').replace(/%2F/g, '/')
console.log({ imageUrl });
return redirectTo(imageUrl, callback)
}

// Return original image if it's static image
if (/_next/.test(query?.url)) {
/* The URL for the original image. */
const imageUrl =
'https://' +
config?.distributionDomainName +
query?.url.replace(/%2F/g, '/')
return redirectTo(imageUrl, callback)
}

// Return original image if it's image/gif or image/svg+xml
const regex = /\.(gif|svg|xml)$/
if (regex.test(query?.url)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs-image-optimization/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/nextjs-image-optimization/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-image-optimization",
"version": "0.2.17",
"version": "0.2.18",
"description": "Image Optimization Lambda",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit fb08e9b

Please sign in to comment.