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

Preload only working on localhost #93

Open
slayer1551 opened this issue Jul 9, 2022 · 1 comment
Open

Preload only working on localhost #93

slayer1551 opened this issue Jul 9, 2022 · 1 comment

Comments

@slayer1551
Copy link

When making API calls from http://localhost:19006 push seems to be working fine and it loads 400 requests in a few seconds however when I try via 192.168.1.181:19006 or on my iOS app making fetch requests it seems to be failing and loading them normally which takes over 30s.
success
failed

I'm using the API Platform Docker for the backend. Any help would be appreciated

@7system7
Copy link

7system7 commented Sep 20, 2022

Hey! Pls, help me. What is your Preload route for the nested requests? There is no documentation about the Preload http header, just a few examples in this documentation... it is so annoying. Btw, I have a running caddy w/ vulcain and push config and I use api-platform as an API.

So, I have this structure:

{
  "@context" : "/api/contexts/Environment",
  "@id" : "/api/environments",
  "@type" : "hydra:Collection",
  "hydra:member" : [
    {
      "@id" : "/api/environments/1",
      "@type" : "Environment",
      "id" : 1,
      "uuid" : "020e8181-6362-485d-bbc5-2714d9d8d19b",
      "name" : "inventore",
      "cpu" : 8000,
      "memory" : 8192,
      "storage" : 100000,
      "project" : "/api/projects/2",
      "provider" : "/api/providers/1",
      "envVar" : [],
      "state" : "/api/states/9",
      "environmentComponent" : [],
      "region" : "/api/regions/1",
      "exportedData" : []
    },
  ],
"hydra:totalItems" : 15,
... and so on

I would like to get the project through push request, so I send the Preload w/ http header AND w/ http param to be sure. Btw, I checked the demo by dunglas.

And I know, the normalization context is not restricted to iri-only:

    defaults:
        normalization_context:
            iri_only: true

But I have correct caddy config:

...
        route {
                root * <root-dir>

                php_fastcgi unix//run/php-fpm/php-fpm.sock
                encode gzip zstd
                file_server

                vulcain
                push
        }
...

The code:

const fetchJson = async (url, opts = {}) => {
  const resp = await fetch(url, {
    headers: {
      Authorization: `Bearer ${window.localStorage.getItem('auth')}`,
      ...opts,
    }
  });
  return resp.json();
};
  
const preload = "/hydra:member/*/@id/project";
const req = await fetchJson(
  `/api/environments?preload=${preload}`,
  { Preload: preload, }
);

for (const envItem of req[ 'hydra:member' ]) {
  const env = await fetchJson(envItem[ '@id' ]);
  const project = await fetchJson(`/api/projects${getId(env.project, '/api/projects')}`);

  console.log(
    project
  );
}

These are not working as Preload path:

  • /hydra:member/*/project/*
  • /hydra:member/*/@id/project

Extra question

Do you know, how to add multiple preload queries? So, what if I want to get project and provider too through push request?

  • comma separated paths /hydra:member/*/project/*,/hydra:member/*/provider/*
  • or space spearated /hydra:member/*/project/* /hydra:member/*/provider/*
  • or special setup option, like css /hydra:member/*/project/*+/hydra:member/*/provider/*
  • or multiple http items
    # as header
    Preload: /hydra:member/*/project/*
    Preload: /hydra:member/*/provider/*
    
    # as param
    ?preload[]=/hydra:member/*/project/*&preload[]=/hydra:member/*/provider/*
    

I think it needs a little more docs. 😆

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

2 participants