Skip to content

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

@Blackvz

Description

@Blackvz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions