Answer the question
In order to leave comments, you need to log in
How to solve the problem with Too many requests in server-side rendering?
There are two servers, one with Laravel is used as an API, the second with Nuxt.js with pre-rendering on the SSR server. The problem is that api data is requested from the server directly, and not from the client (user's browser). This happens because we have SSR mode on Nuxt.js. As a result, when different users access the frontend server, we receive many requests to the backend server as if from one client, namely from our frontend server. From this, the backend server cuts off these requests for an error 424 Too many requests.
Question: what to do so that all requests are not cut off? We need SSR mode for SEO so that Yandex can see the pages of our Site.
Answer the question
In order to leave comments, you need to log in
Configure real ip forward between proxy servers. Example .
Another option: make your own middleware that repeats the standard mechanism for limiting the number of requests, but add an exception for the frontend ip to it.
Forwarding seems to me the most correct solution, but it is not always possible - sometimes the local network is configured crookedly or has a complex structure, and then it is not possible to transfer the external ip.
There is one more nuance: the search bot can still run into these limits, even if you set up the correct ip forwarding - it will simply make more requests than allowed.
Setting up the throttle
middleware Let's make a limit of 5 attempts per minute.
Route::group(['prefix' => 'api', 'middleware' => 'throttle:5'], function () {
Route::get('people', function () {
return Person::all();
});
});
Route::group(['prefix' => 'api', 'middleware' => 'throttle:5,10'], function () {
Route::get('people', function () {
return Person::all();
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question