-
Notifications
You must be signed in to change notification settings - Fork 0
draft #121
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
draft #121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,12 @@ import { useRouter } from "next/router"; | |
| import Script from "next/script"; | ||
| import * as React from "react"; | ||
|
|
||
| import { getUrl } from 'nextjs-current-url'; | ||
|
|
||
| import { Link } from "../components/link"; | ||
|
|
||
| export const djangoBaseUrl = process.env.NEXT_PUBLIC_DJANGO_BASE_URL ?? ""; | ||
| // export const djangoBaseUrl = process.env.NEXT_PUBLIC_DJANGO_BASE_URL ?? ""; | ||
| export const djangoBaseUrl = getUrl({ req: context.req.host }) ?? ''; | ||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCritical: The current implementation has several critical issues:
This change from a static environment variable to dynamic URL retrieval fundamentally changes how
Let me verify how 🏁 Script executed: #!/bin/bash
# Description: Check all usages of djangoBaseUrl to understand the refactoring scope
# Search for all imports and usages of djangoBaseUrl
rg -A 3 "djangoBaseUrl" --type tsx --type ts
# Check if there are any Next.js API routes or getServerSideProps that could provide context
fd -e tsx -e ts -x grep -l "getServerSideProps\|getStaticProps\|export.*async.*function.*handler" {} \;Length of output: 181 🏁 Script executed: #!/bin/bash
# Locate the django-helpers file
file_path=$(fd -t f -e tsx -e ts "django-helpers.tsx" . | head -n 1)
echo "Found file: $file_path"
# Show the top of the file to verify 'context' usage
if [[ -n "$file_path" ]]; then
sed -n '1,200p' "$file_path"
else
echo "django-helpers.tsx not found"
fi
# Search for all references to djangoBaseUrl in the repo
rg "djangoBaseUrl" -n .
# Search for Next.js data-fetching methods or API route handlers that might provide context
rg -n "getServerSideProps|getStaticProps|export\\s+default\\s+function\\s+handler" .Length of output: 6903 Critical: The export on line 18 of export const djangoBaseUrl = getUrl({ req: context.req.host }) ?? '';will throw a You must either:
🤖 Prompt for AI Agents |
||
| export const djangoContentFallback = | ||
| process.env.NEXT_PUBLIC_DJANGO_CONTENT_FALLBACK === "true"; | ||
|
|
||
|
|
||
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
Verify if
nextjs-current-urlis the appropriate package for this use case.Based on the retrieved learnings, Next.js SSR should use
req.headers.hostto get the current domain. Please verify that this package properly handles SSR contexts and provides the correct domain for avoiding CORS issues.🌐 Web query:
💡 Result:
The
nextjs-current-urlnpm package enables you to retrieve the current URL or route in Next.js applications, in both client-side and server-side environments—including in SSR (Server-Side Rendering) contexts[9].How
nextjs-current-urlWorksPurpose:
The package offers utility functions to quickly get the full URL, including protocol, host, path, and query string, regardless of whether your code runs on the server or client[9].
Client Side:
On the client, it typically uses
window.locationto access the full URL.Server Side (SSR):
On the server, it extracts URL information from the request object (
req) available in server-rendering methods likegetServerSidePropsor API routes[2]. This way, you can determine the full URL as seen by the user at request time, which is very useful for SSR scenarios.Example Usage (SSR Context)
Suppose you use
getServerSidePropsin a page:contextcontains the underlying Node.jsreqandresobjects. The package reads from these to construct the correct URL, handling edge cases like proxies or Vercel deployments automatically[9].When to Use
Similar Alternatives
reqobject: You can build the URL manually fromreq.headers, but this requires boilerplate and does not handle all deployment edge cases automatically[2][1].nextjs-urlprovide a similar API for extracting protocol, host, and path from the request both on server and client[1].Limitations and Notes
getServerSideProps,getInitialProps, or API routes) to access thereqobject. It will not work for static site generation (SSG), because at build time there is no incoming HTTP request[1].In summary:
nextjs-current-urlis a convenient utility for getting the entire current URL in Next.js, abstracting away the differences between client and server environments in SSR[9]. It is especially useful in dynamic, server-rendered pages where deducing the user's actual request URL is crucial.Citations:
🏁 Script executed:
Length of output: 5086
Fix SSR retrieval of the Django base URL
The
nextjs-current-urlpackage is perfectly capable of extracting the full URL in both client and SSR contexts, but it must be invoked inside a Next.js SSR lifecycle method (e.g. getServerSideProps) with the actualreqobject—not at module initialization withcontext.req.host, which doesn’t exist here. The current line will throw at build/runtime and won’t reliably prevent CORS issues.• File:
src/shared/django-helpers.tsx• Line: definition of
djangoBaseUrlSuggested fix:
Alternatively, construct the base URL manually in SSR:
• Ensure all downstream code (e.g.
DjangoRedirectOnIframeAuth) readsdjangoBaseUrlfrom props or context where SSR has run.• Keep the import of
getUrlif you move it into SSR—otherwise remove unused imports.• This change guarantees you’re using the real request host (per
req.headers.host) to avoid CORS issues during SSR.🤖 Prompt for AI Agents