#NextJS _middleware

1 messages · Page 1 of 1 (latest)

umbral thistle
#

In my experience - seems like middleware is running on striped down version of some JS interpreter, which is not connected with standard nodejs (on which api routes run).

#

In my case I want create some service, which should load once from external source, redirects.

#

Then I want use _middleware for redirects (works perfect).

#

But I also want to have possibility cache and reload this redirects.

#

I realize that is not possible have one singleton object which store this data for me, because api route and middleware create this object for itself.

#

I solve this by creating API route which provide list of redirects (use this singleton object, for cache and refresh this data) and _middleware internally read this data from API route.