Hosting WebFramework NextJS Rewrite Fallback Fails to fallback

141 views
Skip to first unread message

Kevin Pierce

unread,
Mar 28, 2024, 11:52:22 AM3/28/24
to Firebase Google Group
Expecting that an unsupported hosting rules rewrites will properly be handled in the ssr function using nextjs node server support.

next.config.js
fallback 
source /:path* 
destination https://some-site-to-proxy/:path*


next dev (works)
next build && next serve (works)

firebase hosting deploy (deploys but rewritten paths hang for 60 seconds inside SSR proxy, other non fallback ssr pages render)

Is the expected functionality not actually supported as advertised?

Doc Ramadani

unread,
Mar 28, 2024, 5:30:23 PM3/28/24
to Firebase Google Group
Hi Kevin,

I am developing my own PWA with Next.js 14.0.4 (using the App router). I am using firebase tools version 13.3.1. It works like a charm.

You need to deploy you Next.js app with the command "firebase deploy". This will not only upload your statically rendered files but also instantiate a cloud function that handles the SSR part.

https://firebase.google.com/docs/hosting/frameworks/nextjs

Happy building,
Marco

Kevin Pierce

unread,
Mar 29, 2024, 12:01:23 AM3/29/24
to fireba...@googlegroups.com
Hello Doc,
Thanks for the reply.

I am successfully deploying the next ssr app. Also using the latest next and firebase tools. 

My specific problem is with rewrites in next.config.js.
Are you using any rewrites to external urls?

I ended up solving my problem with a workaround by specifying 
app/[...id]/route.ts for where I want to proxy and put in a route there with a fetch to the remote site and proxy the body in a new Response().

I do think there is a bug around the firebase hosting nextjs rewrites. Specifically to external urls, they should be passed/realized in the deployed cloud function.  The docs and source code for firebase-tools indicate as such.

Cheers,
Kevin

--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/OWhlFepGxjM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/f051f065-5f2d-43ce-9e9d-1f4d3f5ed9een%40googlegroups.com.

Doc Ramadani

unread,
Mar 31, 2024, 10:22:45 AM3/31/24
to Firebase Google Group
Hello Kevin,

ah, understand. Thanks for the clarification.

Since I don't need rewrites to external urls I have not experiences on that. Sorry, that I can help.

But since you wrote that your requests "hang" for 60 seconds I think that your assumption is right and the instanciated cloud function doesn't handle the rewrites correctly. The standard execution time for the cloud function for the next.js ssr is 1 minute (unless you defined something different in your "firebase.json" file).

You should probably file an issue in the firebase-tools GitHub repo:


The contributing developers already did a great job on making next.js deploys on Firebase very easy. I am pretty sure that they'd like to fix issue, too.

Best,
Doc (Marco)

Reply all
Reply to author
Forward
0 new messages