Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Blackvz opened this issue Sep 13, 2024 · 0 comments

Comments

@Blackvz
Copy link

Blackvz commented Sep 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant