Skip to content

[bug] edge server function monorepo environment variable #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lucasvieirasilva opened this issue Jan 3, 2024 · 0 comments
Closed

[bug] edge server function monorepo environment variable #340

lucasvieirasilva opened this issue Jan 3, 2024 · 0 comments

Comments

@lucasvieirasilva
Copy link
Contributor

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:

https://github.com/sst/open-next/blob/3a5755fdcbfdf688cedc355e892b5ed74787993f/packages/open-next/src/adapters/server-adapter.ts#L33-L37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant