-
Notifications
You must be signed in to change notification settings - Fork 169
Description
Issue
When the Next.js project is created using a monorepo structure and deployed using the SST NextjsSite
construct, the server function fails when the region where the user is located is different from the S3 cache bucket.
PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Cause
When OpenNext identifies a monorepo structure, it calls the addMonorepoEntrypoint
function and creates a index.js
exporting the handler inside the project package:
Source reference:
addMonorepoEntrypoint](https://github.com/sst/open-next/blob/3a5755fdcbfdf688cedc355e892b5ed74787993f/packages/open-next/src/build.ts#L712-L725)
SST adds the following code before the export *
and the final code looks like:
process.env = { ...process.env, ..."{{ _SST_FUNCTION_ENVIRONMENT_ }}" };
export * from "./apps/frontend/admin-ui/index.mjs";
However, the way node.js works the imports run before the process.env
block, the CACHE_BUCKET_REGION
is not defined and the S3Client
is defined without the right region: