admin icon indicating copy to clipboard operation
admin copied to clipboard

Too many requests when clicking on a resource for the first time or initially

Open Blackvz opened this issue 1 year ago • 0 comments

API Platform version(s) affected: x.y.z

Backend

v3.3.12

Frontend

"@api-platform/admin": "^4.0.1",

Description
When I click on a resource for the first time a lot of requests will fire. Here I reload the page on a specific resource (http://localhost:3000/#/locations). We also tested in prod mode.

Dev Mode

Bildschirmfoto 2024-09-13 um 10 54 09

Prod Mode

Bildschirmfoto 2024-09-13 um 11 04 05

How to reproduce Its a simple example. I just use a custom httpClient to set a header for the authorization (jwt).

import { HydraAdmin, hydraDataProvider } from "@api-platform/admin";
import { parseHydraDocumentation } from "@api-platform/api-doc-parser";
import { ENTRYPOINT } from "./constants/entrypoint";
import MyHeaders from "./constants/headers";
import httpClient from "./components/HttpClient";

// Replace with your own API entrypoint
// For instance if https://example.com/api/books is the path to the collection of book resources, then the entrypoint is https://example.com/api

const apiDocumentationParser = () => async () => {
  try {
    return await parseHydraDocumentation(ENTRYPOINT, {
      headers: MyHeaders
    });
  } catch (result) {
    // @ts-ignore
    const { api, response, status } = result;
    if (status !== 401 || !response) {
      throw result;
    }

    return {
      api,
      response,
      status,
    };
  }
};

const dataProvider = hydraDataProvider({
  entrypoint: ENTRYPOINT,
  httpClient: httpClient,
  apiDocumentationParser: apiDocumentationParser(),
  useEmbedded: false,
});

export default () => (
  <HydraAdmin dataProvider={dataProvider} />
);

Additional Context

Blackvz avatar Sep 13 '24 09:09 Blackvz