Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Critical: SSR compatibility issue and security concern.
This change introduces two critical problems:
SSR Error:
window.location.originwill cause "ReferenceError: window is not defined" during server-side rendering in Next.js.Security Risk: Using the current window origin as the Django base URL means the application will trust whatever domain it's running on, potentially enabling malicious redirects.
Consider reverting to the environment variable approach or add proper runtime guards:
If runtime determination is required, use a function with proper guards:
Let me verify how this constant is used across the codebase:
🏁 Script executed:
Length of output: 820
#!/bin/bash
Search for all import sites of the shared django-helpers module
echo "=== Imports of src/shared/django-helpers.tsx ==="
rg "from .*shared/django-helpers" -n
List any pages or API routes using SSR data-fetching methods
echo -e "\n=== Files defining getServerSideProps ==="
rg "getServerSideProps" -n
echo -e "\n=== Files defining getStaticProps ==="
rg "getStaticProps" -n
Check if any SSR file imports django-helpers
echo -e "\n=== SSR files that import shared/django-helpers.tsx ==="
rg "from .*shared/django-helpers" -l | xargs -r rg -n "getServerSideProps|getStaticProps"
#!/bin/bash
Search for all usages of djangoBaseUrl in the repository
echo "=== Searching for djangoBaseUrl usages ==="
rg "djangoBaseUrl" -n .
Search for imports of the django-helpers module
echo -e "\n=== Searching for imports of shared/django-helpers.tsx ==="
rg "shared/django-helpers" -n .
List all files using Next.js SSR/SSG methods
echo -e "\n=== Files with getServerSideProps ==="
rg "getServerSideProps" -n .
echo -e "\n=== Files with getStaticProps ==="
rg "getStaticProps" -n .
echo -e "\n=== Files with getInitialProps ==="
rg "getInitialProps" -n .
🏁 Script executed:
Length of output: 3713
Fix SSR/Server-side Import of djangoBaseUrl
The switch to
window.location.originbreaks any server‐side or API‐route imports ofdjangoBaseUrl(e.g.src/pages/api/rewrites/proxy-django-html-page.tsx), sincewindowis undefined in Node and during SSR.• Affected locations:
• Proposed fix: turn the constant into a guarded function that falls back to the env var on the server:
Then update all imports/usages:
And in the API route:
Optionally, use a non-public server‐only env var (e.g.
DJANGO_BASE_URL) instead of aNEXT_PUBLIC_one for stronger configuration control.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexander-mart Для получения текущего домена в SSR и поддержки нескольких доменов, вам нужно использовать заголовки запроса. Вот несколько подходов:
1. Универсальная функция для получения домена
2. В getServerSideProps
3. В API routes
4. Для клиентских запросов без CORS
5. С использованием Next.js middleware (рекомендуется)
Затем в компонентах:
Обновлённая версия django-helpers.tsx
Такой подход:
✏️ Learnings added