QueraTeam / django-nextjs

Next.js integration for Django projects
MIT License
341 stars 17 forks source link

Issues when running the Django server in production mode #3

Closed ISilviu closed 2 years ago

ISilviu commented 2 years ago

Hi,

If the Django server is set to run with debug=False, then all the requests will pass through the render_nextjs_page_sync, according to this statement in urls.py:

if settings.DEBUG:
    # only in dev environment
    urlpatterns.append(re_path(r"^(?:_next|__nextjs|next).*$", NextJSProxyView.as_view()))

The problem is that all the .js bundles requests will have their content-type property set to text/html, as this is happening for each request that passes through this view:

from django_nextjs.render import render_nextjs_page_sync

def index(request):
    return render_nextjs_page_sync(request)

Should the content-type be manually computed and then specified as an argument to the render_nextjs_page_sync method? I don't see other way around it.

Thank you!

danialkeimasi commented 2 years ago

Hi,

There is no need to proxy these things within the Django server in the production environment. Rather than introducing an unnecessary load on the Django server, you can use your web server's file serving to serve the Nextjs build files and reverse proxy to route related URLs directly to the Nextjs server.

Search for "reverse proxy" in the README.md, we've already covered that.

ISilviu commented 2 years ago

Hi,

I am already using a reverse proxy within the Apache server, yet the requests still seem to pass through the Django, since they always have text/html as content-type. Then, I suspect there is a configuration issue in the Apache server.

Thank you!