amannn/next-intl

Middleware not working with Firebase Hosting emulator

cosmicproc opened this issue · 2 comments

Description

When using Firebase Hosting emulator, the next-intl middleware seems to be not working properly. When the emulator is started, it looks like the server is trying to redirect the user to the same URL forever.

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://github.com/cosmicproc/next-intl-firebase-hosting-emulator-bug/

Reproduction description

Steps to reproduce:

  1. Clone the reproduction repository.
  2. Install the dependencies with npm install .
  3. Install firebase-cli with npm install -g firebase-tools.
  4. Run the emulator with firebase emulators:start inside the repository.
  5. Open the emulator webpage (http://localhost:5000).
  6. Observe that it doesn't load and eventually returns the message "Internal Server Error".
  7. Observe that after a while, the terminal output is flooded with messages from the Firebase Hosting emulator telling something like 127.0.0.1 - - [19/Apr/2024:16:07:11 +0000] "GET /en HTTP/1.1" 500 - "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
  8. Remove the middleware and observe that this issue no longer happens.
  9. Observe that everything works as normal when npm run dev is run instead.

Expected behaviour

Redirect users to the appropriate URLs properly as usual.

I just found https://firebase.google.com/docs/hosting/manage-cache#using_cookies. I think it's because of that. It looks like custom cookies can't be used with Firebase Hosting.
I am not sure could it be fixed. Can close the issue if this is out of scope.

Update:
I tried this middleware with the emulator and it looks like cookies are available. I don't know what's the problem then.

export default function middleware(req) {
    console.log(req.cookies);
}

I no longer need this. Thanks for the great library by the way.