Skip to content
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

Problem using deployed server-function from open-next when using basePath #476

Closed
yiytan92 opened this issue Jul 19, 2024 · 10 comments · Fixed by #485
Closed

Problem using deployed server-function from open-next when using basePath #476

yiytan92 opened this issue Jul 19, 2024 · 10 comments · Fixed by #485

Comments

@yiytan92
Copy link

yiytan92 commented Jul 19, 2024

Does anyone use the basePath configuration in their next.config.js?

I am migrating to use open-next for deployment from using serverless-nextjs and facing an issue after deploying the server function onto Lambda.

For example, in my next.config.js i have a basePath: "/basePath", and a page named index
When i deploy the open-next server function onto a lambda url function and try to access the page with the basePath https://example.lambda-url.ap-southeast-1.on.aws/basePath/index, it returns me 404.
however accessing https://example.lambda-url.ap-southeast-1.on.aws/index routes properly.

Looking at how the serverless-nextjs library did it, they have a function to slice away the basePath in the lambda function handler: https://github.com/serverless-nextjs/serverless-next.js/blob/e6367b585fb98608cd2e9327e2c8d4058ba73b00/packages/libs/core/src/route/basepath.ts

Have i misconfigured something on my open-next setup?

@conico974
Copy link
Collaborator

This is not done on the server function in OpenNext.
OpenNext creates an open-next.output.json file in the output folder (i.e. .open-next) with a behaviors field that should already contains the basePath that you can use directly as a cloudfront behavior.
You can take a look at the cdk implementation used for e2e test https://github.com/sst/open-next/blob/main/examples/sst/stacks/OpenNextReferenceImplementation.ts

@jarodsim
Copy link

Does anyone use the basePath configuration in their next.config.js?

I am migrating to use open-next for deployment from using serverless-nextjs and facing an issue after deploying the server function onto Lambda.

For example, in my next.config.js i have a basePath: "/basePath", and a page named index When i deploy the open-next server function onto a lambda url function and try to access the page with the basePath https://example.lambda-url.ap-southeast-1.on.aws/basePath/index, it returns me 404. however accessing https://example.lambda-url.ap-southeast-1.on.aws/index routes properly.

Looking at how the serverless-nextjs library did it, they have a function to slice away the basePath in the lambda function handler: https://github.com/serverless-nextjs/serverless-next.js/blob/e6367b585fb98608cd2e9327e2c8d4058ba73b00/packages/libs/core/src/route/basepath.ts

Have i misconfigured something on my open-next setup?

Im with the same issue :/

@conico974
Copy link
Collaborator

@jarodsim What issue ?? This is not meant to be done in OpenNext but by the IAC.
This is working in Ion since OpenNext 3.0.0-rc.8

@jarodsim
Copy link

jarodsim commented Jul 19, 2024

@jarodsimQual problema?? Isso não deve ser feito no OpenNext, mas pelo IAC. Isso está funcionando no Ion desde o OpenNext 3.0.0-rc.8

Oh, sorry

I'll take a look at SST, thanks

@conico974
Copy link
Collaborator

No problem, just use the behavior defined in the open-next.output.json in cloudfront and it should work

@yiytan92
Copy link
Author

Hi @conico974, thanks for replying. I took a look at the open-next.output.json output, and verified that my current cloudfront behaviors matches it. Regardless of the cloudfront, when i invoke the lambda directly with my lambda function url it faces this basePath issue.

https://example.lambda-url.ap-southeast-1.on.aws/basePath/index returns 404.
https://example.lambda-url.ap-southeast-1.on.aws/index routes properly.

Would you happen to know if there's any examples of deploying the open-next server-functions to lambda with basePath working?

@conico974
Copy link
Collaborator

@yiytan92 Does it work if you invoke it through cloudfront ?
And if you want to test it you can use sst ion it works there last time i tested.

What version of OpenNext are you using BTW ? This PR might cause some issue with basePath #426. Try with 3.0.2 if you're on latest

@yiytan92
Copy link
Author

yiytan92 commented Jul 19, 2024

Doesn't work when invoked via cloudfront either.

https://cloudfront.net/basePath/index returns 404.
https://cloudfront.net/index routes properly.

I have deployed open-next webs without baseUrl and it works fine, that's why i suspect its a basePath handling issue. I am using OpenNext v3.0.6.

And if you want to test it you can use sst ion it works there last time i tested.

Ok, will try that and report back, thanks for the suggestions!

@eschaefer
Copy link

eschaefer commented Jul 31, 2024

Just chiming in since I'm facing the exact same issue. Using OpenNext 3.0.8 via SST ion.

Not related to using server functions, but rather:
cloudfront.net/basePath/index returns 404.
cloudfront.net/index routes properly.

Can confirm that pinning openNextVersion: "3.0.2", on SST ion fixes the issue.

@yiytan92
Copy link
Author

yiytan92 commented Aug 2, 2024

Hey, thanks @eschaefer, after reading your comment, i also fixed my open-next version to 3.0.2 and the issue is fixed.
@conico974 FYI

#426

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

Successfully merging a pull request may close this issue.

4 participants