When we have to publish the same website to different channels (for say, different languages), we create a channel, associate it with the website, published everything in that channel, and set the url. And if we are using the same domain for both the channels,
we set a prefix. For example, we have a domain example.com
, this will be used for the default channel. Now we create a new channel for English, with a prefix en
. Now this can be accessed at example.com/en
.
Ideally we should expect both these routes to work, with example.com
serving the default homepage and example.com/en
serving the English homepage.
Currently we can access the default home page by going to example.com
. But accessing the new channel prefix, example.com/en
gives a not found error, consequently a 429: Too many requests
error.
β Compiling /not-found ...
β Compiled /not-found in 1082ms (1680 modules)
[GraphQL Network error for url https://example.com/storefront.graphql]: ServerError: Response not successful: Received status code 429
Stack: ServerError: Response not successful: Received status code 429
at throwServerError (webpack-internal:///(rsc)/./node_modules/@apollo/client/link/utils/throwServerError.js:6:17)
at parseJsonBody (webpack-internal:///(rsc)/./node_modules/@apollo/client/link/http/parseAndCheckHttpResponse.js:133:74)
at eval (webpack-internal:///(rsc)/./node_modules/@apollo/client/link/http/parseAndCheckHttpResponse.js:187:20)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
β¨― node_modules\@apollo\client\errors\index.js (39:27) @ call
β¨― ApolloError: Response not successful: Received status code 429
at new Promise (<anonymous>)
at Array.forEach (<anonymous>)
We tried sending a getContentType query using Banana Cake Pop from example.com/en
. And it responds with a Redirect
. And then we tried example.com/en/
This time however, the response was HomePage
. So itβs just a single fore-slash (/) that we need to avoid this redirect loop.
middleware:
This time I tried making the following changes in middleware.ts
to add a β/β at the end of the url
url: `${request.nextUrl.pathname}/?${request.nextUrl.searchParams}`
And, It worked.
This time however got another error
The HomePage Template:
The templates will send a getContent query to the API, here also the β/β was causing it to get a redirect
Instead of the content.
await queryWithHeader({
query: GET_CONTENT,
url: params.slug?.join('/') ?? '/',
headers: headers(),
})
).content;
return await createMetadataFromUrl(params.slug?.join('/'), headers());
So, I made changes to both of them as well
await queryWithHeader({
query: GET_CONTENT,
url: `${params.slug?.join('/')}/` ?? '/',
headers: headers(),
})
).content;
return await createMetadataFromUrl(
`${params.slug?.join('/')}/` ?? '/',
headers()
);
It was a success; Accessing example.com/en/
now responded with the home page.
But this caused the default homepage to crash
Litium version: 8.13.0
React accelerator: 1.0.0-rc-02