QueraTeam / django-nextjs

Next.js integration for Django projects
MIT License
351 stars 18 forks source link

Fix NextJS 13 + AppRouter client-side navigation #28

Closed RobbieFernandez closed 1 year ago

RobbieFernandez commented 1 year ago

This PR implements the changes I mentioned in issue #27, namely forwarding the required headers along to the NextJS server, and extracting the required headers from its response.

I also wanted to note that in order for nginx to forward the Rsc header to Django, you need something like the following:

    location / {
        set $upstream_app MY_DJANGO_URL;
        proxy_pass http://$upstream_app:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-Ip $proxy_add_x_forwarded_for;
        proxy_pass_header Rsc;  # < ----- This needs to be added
    }

I think this is worth documenting since the README has a recommended nginx config already but I wasn't sure how best to include it since the sample config doesn't have a location block for Django.