Ilja
Ilja

Reputation: 46509

Renaming next's output folder from "_next" to "next"

I came across use-case today where I was trying to get my nextjs app working in android webview, unfortunately android doesn't resolve paths that begin with _next and most of my chunk files are under _next/static when I build my app.

Is there a way to to rename this folder from _next to next or anything else? This issue will give extra context about how android works in this regard Android project is not resolving any static assets

Upvotes: 4

Views: 3219

Answers (1)

Nimit Mak
Nimit Mak

Reputation: 11

I handled this issue via Nginx Routing.

What i assumed while making this Nginx Routing is that every file will have unique hash and file name combination.

This is the snippet of code of Nginx Routing which i used.

location /static/ {
    try_files $uri @server1;
}
location @server1{
    proxy_pass http://192.168.1.1$uri;
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 = @server2;
}

location @server2{
    proxy_pass http://192.168.1.2$uri;
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 = @server3;
}

location @server3{
    proxy_pass http://192.168.1.3$uri;
}

What the above code does is, whenever Nginx encounters /_next/ it will first try that URL with @server1, if that Server responds with 404, the Nginx then transfers the request to @server2 as mentioned in error_page param.

This example works like: try_files $uri @server1 @server2 @server3

This worked for me as i had 2 apps which were developed on Next and both has _next route.

Let me know if this solves your problem.

Upvotes: 1

Related Questions