You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hi, I am working on a Multi-Tenant App, and the content of the tenant is served based on the host, so the host is set as a header in each request sent to the API:
constresult=awaitaxios({
url,headers: {
...headers,//passing the tenant host as a header"X-Tenant-Domain": appState.tenantHost},
method,
data,
params
});
and I am having an issue with how should I set next-i18nextup.
I have made the general setup, like setting up next-i18next config, wrapping the app in appWithTranslation, and using serverSideTranslations. but the issue is when too many requests are sent at the time to the server, it does not set the headers at all and the requests are sent from the client, not the server.
here is what my setup looks like: _app.tsx:
import{serverSideTranslations}from'next-i18next/serverSideTranslations'importi18nextConfigfrom"@/next-i18next.config.js";exportconstgetServerSideProps=async({ locale, req })=>{consthost=req.headers.host;//HERE set the custom header for the backend, to the i18next instancei18nextConfig.backend.backendOption.customHeaders={"X-Tenant-Domain": host};return{props: {
...(awaitserverSideTranslations(locale,["common","footer"],i18nextConfig))}};};
next-i18next.config.js:
constHttpBackend=require("i18next-http-backend/cjs");constMultiLoadBackendAdapter=require("i18next-multiload-backend-adapter/cjs");const{ axios }=require("./lib/axios");constenv=process.env.NODE_ENV;module.exports={i18n: {locales: ["ar","en"],defaultLocale: "ar"},ns: [...],defaultNS: "common",maxParallelReads: 30,serializeConfig: false,reloadOnPrerender: env==="development",use: [MultiLoadBackendAdapter],backend: {backend: HttpBackend,backendOption: {loadPath: "{{lng}}|{{ns}}",customHeaders: {},request: async(options,url,payload,callback)=>{try{const[lng,ns]=url.split("|");awaitaxios.get("/translations",{params: {group: ns.split("+")},//passing the tenant host as a header, and here sometimes the headers are emptyheaders: options.customHeaders}).then((response)=>{callback(null,{data: response.data.data,status: 200});}).catch((error)=>{callback(null,{status: 500});});}catch(e){callback(null,{status: 500});}}}}};
and IDK why in some cases the translations are fetched from the client, not the server, and I could not set the headers because I do not have the correct i18nextConfig instance to attach the headers to it.
can anyone help me with this issue to find out what is happening here? I really searched all over Google and made lots of logs and debugging and I could not anything to help resolve the issue.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hi, I am working on a Multi-Tenant App, and the content of the tenant is served based on the host, so the host is set as a header in each request sent to the API:
and I am having an issue with how should I set
next-i18next
up.I have made the general setup, like setting up
next-i18next
config, wrapping the app inappWithTranslation
, and usingserverSideTranslations
. but the issue is when too many requests are sent at the time to the server, it does not set the headers at all and the requests are sent from the client, not the server.here is what my setup looks like:
_app.tsx
:in each page's
getServerSideProps
:next-i18next.config.js
:and IDK why in some cases the translations are fetched from the client, not the server, and I could not set the headers because I do not have the correct
i18nextConfig
instance to attach the headers to it.can anyone help me with this issue to find out what is happening here? I really searched all over Google and made lots of logs and debugging and I could not anything to help resolve the issue.
Beta Was this translation helpful? Give feedback.
All reactions