Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

fix(nextjs-component): don't override _next/image* and _next/static/*… #859

Merged
merged 2 commits into from
Jan 2, 2021
Merged
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
8 changes: 4 additions & 4 deletions packages/e2e-tests/next-app/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ next-app:
inputs:
build:
postBuildCommands: ["node scripts/post-build-test.js"]
imageOptimizer: true
cloudfront:
defaults:
forward:
headers: [Accept] # Needed for image optimizer
_next/static/*:
defaultTTL: 0
minTTL: 0
maxTTL: 0
12 changes: 8 additions & 4 deletions packages/serverless-components/nextjs-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,16 @@ class NextjsComponent extends Component {
};

// here we are removing configs that cannot be overridden
if (path === this.pathPattern("api/*", routesManifest)) {
// for "api/*" we need to make sure we aren't overriding the predefined lambda handler
if (
path === this.pathPattern("api/*", routesManifest) ||
path === this.pathPattern("_next/image*", routesManifest)
) {
// for "api/*" or "_next/image*" we need to make sure we aren't overriding the predefined lambda handler
// Since these are using special API or Image handlers
// delete is idempotent so it's safe
delete edgeConfig["origin-request"];
} else if (!["static/*", "_next/*"].includes(path)) {
// for everything but static/* and _next/* we want to ensure that they are pointing at our lambda
} else if (!["static/*", "_next/static/*", "_next/*"].includes(path)) {
// for everything but _next/static/*, static/* and _next/* we want to ensure that they are pointing at the default lambda
edgeConfig[
"origin-request"
] = `${defaultEdgeLambdaOutputs.arn}:${defaultEdgeLambdaPublishOutputs.version}`;
Expand Down