Next.js + Subdirectory

Continuing the discussion from [Support Guide] Can I deploy multiple repositories in a single site?:


We have a setup like described in the link above where we proxy a site redirect a second Netlify site running on a subdirectory. Both sites are different GitHub repositories.

The problem is now, that any deploy preview for the site running on the subdirectory doesn’t include the required path and - given there’s no initial build failure - will always render the root path instead and report back a successful deploy preview, which can then trigger auto-merging of renovate PRs (like an upgrade to next.js where this happened to us).

We are using the Netlify Next.js plugin (v4.40.1) so I don’t see the option currently of configuring it as it’s described to do for monorepos, using a publish and build directory. Is there a way to set up what we desire?

Hiya @AileenCGN ,

If you’re following the advice in the Support Guide you linked, the secondary/subdirectory site will be entirely contained in the subdirectory - right?

If so, I think that:

  • should 404 - right?
  • and you’d have a redirect for /thatsubdirectory to your SSR function (/thatsubdirectory/* /.netlify/functions/__netlify-handler 200) - which function would then return the appropriate status code (could be 404 or 200 or 419, whatever you code it to return).

If that is what you have configured and you wanted to give us a link to the sites we’d be able to take a bit closer look.

Hey @fool

Yes, correct. Our site is successfully running with the subdirectory. The setup works fine and without problems.

The issue we’re facing is more regarding deploy previews. The Netlify Github integration ignores the subdirectory and reports a successful build (which leads to auto merge and auto deploys) even though the site is experiencing runtime errors when actually then opened with the subdirectory. In the previews we’re only seeing the default Netlify 404 page.

Our root site is running on HUGO:

The subdirectory site is running on Next.js with the page router and the Netlify Next.js Plugin under the subdirectory /explore

Hi @AileenCGN,

Apologies for the delay on this one. I’m still slightly confused by your description though. So is your problem that GitHub checks aere turning green when they shouldn’t OR that you’re seeing some errors when browsing your site?

If it’s the former, could you share some more details like screenshots, links to the relevent deploys, etc.?

If it’s the latter, please let us know how to see the runtime error you’re seeing.

I tried visiting a preview: Page Not Found (deploy-preview-216–, but didn’t see a 404.

Apologies for being not clear enough. Yes it is that GitHub checks are reported green, because they only check the root domain which isn’t in use for this site due to the subdirectory setup.

The auto-merge with renovate upgraded to the next Next.js minor version, which caused the runtime crash, but only when the site is opened on the subdirectory.

The link you posted goes directly to /explore, but all the deploy preview links go to the root domain by default.

Here’s an example of the broken link with showing the default Netlify “Page not Found” which is what results in a green light build, but this is the actual broken result when opening the same link with the subdirectory:

I hope that made it clearer. It would be fantastic if there was a setting to configure the deploy previews to take the subdirectory always into account.

Interesting, I’m not sure if it’s possible, but I’ll try adding a feature request. Not sure if you’re aware, but in your Pull Request comments, you can add text like @netlify/explore and the deploy preview link would automatically take you to that path on your site instead of the home page. Maybe that would already help in this case?