-
Notifications
You must be signed in to change notification settings - Fork 138
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
Rewrites in next.config.js doesnt work #263
Comments
Should be fixed in #261, will release 2.2.2 soon. If not please reopen |
Thank you 🙏🏼🙏🏼🙏🏼 |
@khuezy Should we reopen as the issue still exists in sst 2.30.2 and next 13.5.6 |
See: #261 (comment) According to the E2E test, |
I'm still experiencing that (some) rewrites do not work with next.config.js and SST, it seems like they don't work at all and I get 404 errors. Rewrites are all simple "afterFiles" rewrites with source, destination and Downgrading back to Next.js 13.4 (without touching SST etc.) works. I can try to build a small reproduction later this month. |
There is an error w/ external rewrites, we can reopen this ticket. |
@topaxi |
The types might be incorrect. .getHeaders doesn't exist, it's in req.headers. |
One things that is really weird is that the same code work locally, but not on lambda. During my test i've tried running a fetch in lambda and a fetch locally, in lambda it returns a bunch of symbols and locally it works fine. Not sure what's going on here |
I had the same issue on Update: The simple rewrites such as below works const nextConfig = {
rewrites: async () => [
{ source: "/rewrite", destination: "https://github.com" },
],
}
module.exports = nextConfig But not for the more complex one which has query string involved. Take Sentry as an example (source): const injectedRewrite = {
// Matched rewrite routes will look like the following: `[tunnelPath]?o=[orgid]&p=[projectid]`
// Nextjs will automatically convert `source` into a regex for us
source: `${tunnelPath}(/?)`,
has: [
{
type: 'query',
key: 'o', // short for orgId - we keep it short so matching is harder for ad-blockers
value: '(?<orgid>\\d*)',
},
{
type: 'query',
key: 'p', // short for projectId - we keep it short so matching is harder for ad-blockers
value: '(?<projectid>\\d*)',
},
],
destination: 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0',
}; |
@caaatisgood ~~Thanks, I will try this and update back here ~~ |
Retried with Haven't had the time yet to create a minimal reproduction, this currently blocks us in several ways, so I hope I can spend some time to debug further and provide a reproduction. |
I can confirm i'm observing the same issue with trying to configure Sentry with
|
same issue on [email protected], [email protected] |
Not working in both middleware or next.config.js in [email protected] |
@ianschmitz looks like open-next isn't properly passing the regex group to the destination URL eg: Can you help debug why around this function: https://github.com/sst/open-next/blob/main/packages/open-next/src/adapters/routing/matcher.ts#L122-L170 |
There is a workaround for the sentry issue by using the middleware if (request.nextUrl.pathname.startsWith('/monitoring')) {
const orgId = request.nextUrl.searchParams.get('o');
const projectId = request.nextUrl.searchParams.get('p');
return NextResponse.rewrite(new URL(`https://o${orgId}.ingest.sentry.io/api/${projectId}/envelope/?hsts=0`));
} We need to be careful with this sentry rewrite, if we don't do it properly it can create a security risks since people could use this to rewrite to external url. @raducostea @debu99 First things to check is if you're building on windows, open-next doesn't work well there and it causes a bunch of weird issues. You can use WSL there it should work. |
following as rewrites is confirmed still not working with next 14.1.0 |
@danjiro Could you provide a reproduction ? |
A simple rewrite works locally but not when deployed to AWS. Using Next14.1.0, sst 2.40.6.
gets |
@danjiro This issue should be fixed in V3 rc, could you test it and see if you still have the issue. This issue doesn't always occur as well, i think the issue exists when the external target rewrites uses br or gzip encoding by default |
* should fix most of #263 * added e2e test * directly return * Create fluffy-lamps-confess.md
@conico974 I believe I am still running into this issue when trying to implement a proxy for posthog analytics. It uses external rewrites and gzip encoding Using Next v14.2.3 and OpenNext v3.0.0-rc.16 my next.config looks like
and I am only getting a Following these docs as a guide I think it may be the gzip specifically because a few requests with base64 compression still work find |
@ghardin1314 Could you create a new issue ? There is like 5 different issues here, and all of them are solved or does not have a reproduction. |
This issue still not fixed, wondering why is closed, just tried with sst:ion and next 14.2, rewrites don't work at all. it is literally a hello world app... |
@mateo500 can you put up a min repro? There is an e2e test to cover the next.config.js rewrite config: https://github.com/sst/open-next/blob/main/packages/tests-e2e/tests/pagesRouter/rewrite.test.ts |
All the issues in this thread are either fixed or does not have a reproduction. Did you try with the latest version of OpenNext ? And you're not using windows ? |
After updating Next.js to 13.5.3 to handle a bad error in production (500, attemp to render client in the server). The following stopped working:
redirects: () => {
const SIGNIN_ROUTE =
/login
;const DEFAULT_ROUTE =
/dashboard
;return [
{
source:
/
,destination: DEFAULT_ROUTE,
permanent: true,
has: [{type:
cookie
, key:next-auth.session-token
}],},
{
source:
/
,destination: DEFAULT_ROUTE,
permanent: true,
has: [{type:
cookie
, key:__Secure-next-auth.session-token
}],},
{
source:
/
,destination: SIGNIN_ROUTE,
permanent: true,
missing: [{type:
cookie
, key:__Secure-next-auth.session-token
}],},
{
source:
/
,destination: SIGNIN_ROUTE,
permanent: true,
missing: [{type:
cookie
, key:next-auth.session-token
}],},
];
I am in a damn loop hole, for few weeks already.
My original issue was Next trying to generated protected pages during ISG, and then caching a 500 result.
Then I updated next.js and sst to the latest stable versions (13.5.4, sst 2.26.10).
My folder setup is as following:
src
├── app
│ ├── @authenticated
│ ├── @login
│ ├── _components
│ ├── _hooks
│ ├── _lib
│ ├── api
│ ├── layout.tsx
│ ├── loading.tsx
│ ├── page.tsx
│ └── providers.tsx
└── middleware.ts
Then my root layout conditionally renders login/auth.
Everything works as expected except the root dir "/" which is an empty route.
NextAuth should redirect to '/login' and next itelsf to 'dashboard'.
It works locally without setting next.config.ts.
I tried adding the same login in the middleware but it doesnt seem like the middleware is even running (not seeing any logs form there).
It gets a successful response from '/api/auth/session' but the redirect doesnt happen :/ Any ideas?
The text was updated successfully, but these errors were encountered: