dunglas / vulcain

🔨 Fast and idiomatic client-driven REST APIs.
https://vulcain.rocks
GNU Affero General Public License v3.0
3.52k stars 104 forks source link

Aucun preload ne fonctionne #88

Closed bagullana closed 2 years ago

bagullana commented 2 years ago

Bonjour,

Je viens de découvrir le protocole et je le trouve super intéressant ! Maintenant j'aimerais le mettre en application, et c'est là que ça se corse.

J'ai une API construite via API Platform, et un front fait avec ReactJS qui vient interroger mon API via la gateway vulcain. J'ai beau envoyer mon header Preload, je n'arrive pas à faire fonctionner le multiplexing http2. Je dois passer à côté de quelque chose de tout bête... La gateway est accessible sur https://localhost:8443 et qui tape sur mon api qui se trouve sur http://localhost/api Mon premier appel à GET https://localhost:8443/api/produits renvoie ceci :

[
  {
    "id": 1,
    "cle": 121206,
    "type_cle": 23,
    "label_home_cle": 814,
    "gamme_cle": "737",
    "nb_max": 5,
    "pieces": 2,
    "chambres": 1,
    "sdb": 1,
    "surface": 35,
    "photos": [...],
    "criteres": [...],
    "translations": [...],
    "residence": "/api/residences/1",
    "availabilities": [
      "/api/availabilities/1",
      "/api/availabilities/2",
      "/api/availabilities/3",
      ...
    ],
    "typeCle": 23,
    "labelHomeCle": 814,
    "gammeCle": "737",
    "nbMax": 5
  }
]

J'ai passé en en-tête {Preload: "/api/produits/*/availabilities/*"} Dans Chrome je vois bien qu'il a envoyé une "Requête préliminaire". Mais quand je boucle sur les "availabilities" pour en récupérer les infos, j'ai autant d'ajax qui son relancés. Voici le bout de JS en question :

return await axios.get('https://localhost:8443/api/produits', {
            params: apiParams,
            headers: {Preload: "/api/produits/*/availabilities/*"}
        }).then(async results => {
            let i = 0;
            for (const product of results.data) {
                for (const availability of product.availabilities) {
                    await axios.get('https://localhost:8443' + availability);
                    console.log(availability);
                    i++;

                    if (i > 10) return results.data;
                }
            }
            return results.data;
        });

Et voici le contenu de ma timeline chrome : image

Cela fait plusieurs heures que je patauge sur ce problème, sans comprendre ce qui cloche. Toute aide serait la bienvenue. Merci d'avance.

bagullana commented 2 years ago

J'ai pu avancer et faire presque faire marcher le preload en changeant mon bout de code de test. Ainsi, en procédant comme suit :

        const productResp = await fetch("https://localhost:8443/api/produits/1", {
            headers: {
                Preload: `"/residence"`,
            }
        });
        const product = await productResp.json();
        console.log(product);

        const residence = await fetch('https://localhost:8443' + product.residence);
        console.log(residence.json())

ma requête initiale sur produits/1 reste bloquée : image

Et lorsque je regarde les logs du conteneur Vulcain je vois ceci :

172.18.0.1 - - [19/Jan/2022:22:39:23 +0000] "OPTIONS /api/produits/1 HTTP/2.0" 200 23 "https://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
2022-01-19T22:39:23.266669800Z {"level":"error","ts":1642631963.266287,"caller":"vulcain/server.go:82","msg":"http: proxy error","error":"context canceled","stacktrace":"github.com/dunglas/vulcain.(*server).ServeHTTP.func2\n\t/home/runner/work/vulcain/vulcain/server.go:82\nnet/http/httputil.(*ReverseProxy).ServeHTTP\n\t/opt/hostedtoolcache/go/1.15.2/x64/src/net/http/httputil/reverseproxy.go:290\ngithub.com/dunglas/vulcain.(*server).ServeHTTP\n\t/home/runner/work/vulcain/vulcain/server.go:94\ngithub.com/gorilla/handlers.CompressHandlerLevel.func1\n\t/home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/compress.go:100\nnet/http.HandlerFunc.ServeHTTP\n\t/opt/hostedtoolcache/go/1.15.2/x64/src/net/http/server.go:2042\ngithub.com/gorilla/handlers.loggingHandler.ServeHTTP\n\t/home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/logging.go:47\ngithub.com/gorilla/handlers.recoveryHandler.ServeHTTP\n\t/home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/recovery.go:78\nnet/http.serverHandler.ServeHTTP\n\t/opt/hostedtoolcache/go/1.15.2/x64/src/net/http/server.go:2843\nnet/http.initALPNRequest.ServeHTTP\n\t/opt/hostedtoolcache/go/1.15.2/x64/src/net/http/server.go:3415\nnet/http.(*http2serverConn).runHandler\n\t/opt/hostedtoolcache/go/1.15.2/x64/src/net/http/h2_bundle.go:5718"}
2022-01-19T22:39:23.266736700Z 172.18.0.1 - - [19/Jan/2022:22:39:23 +0000] "GET /api/residences/1 HTTP/2.0" 502 0 "https://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"

Je ne comprends pas le context canceled qui suit la 200 OPTIONS sur /api/produits/1 ainsi que la 502 GET sur /api/residences/1

Renrhaf commented 1 year ago

Hello @bagullana, pourrais tu me dire quelle a été ta solution ? Merci !

Voici l'erreur que je reçois lors d'un upload d'un gros fichier :

2023-10-18 00:01:30 sceneario_backend_api       | 2023/10/17 22:01:30 [warn] 26#26: *189 a client request body is buffered to a temporary file /var/cache/nginx/client_temp/0000000037, client: 172.18.0.11, server: , request: "POST /uploads HTTP/1.1", host: "sceneario-api.saas-production.loc", referrer: "https://sceneario-client.saas-production.loc/"
2023-10-18 00:01:30 sceneario_backend_api       | 172.18.0.11 - - [17/Oct/2023:22:01:30 +0000] "POST /uploads HTTP/1.1" 400 0 "https://sceneario-client.saas-production.loc/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0"
2023-10-18 00:01:30 sceneario_backend_vulcain   | 2023-10-17T22:01:30.332Z      ERROR   vulcain/server.go:89    http: proxy error       {"error": "context canceled"}
2023-10-18 00:01:30 sceneario_backend_vulcain   | github.com/dunglas/vulcain.(*server).ServeHTTP.func3
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /home/runner/work/vulcain/vulcain/server.go:89
2023-10-18 00:01:30 sceneario_backend_vulcain   | net/http/httputil.(*ReverseProxy).ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /opt/hostedtoolcache/go/1.21.1/x64/src/net/http/httputil/reverseproxy.go:475
2023-10-18 00:01:30 sceneario_backend_vulcain   | github.com/dunglas/vulcain.(*server).ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /home/runner/work/vulcain/vulcain/server.go:102
2023-10-18 00:01:30 sceneario_backend_vulcain   | github.com/dunglas/vulcain.(*server).chainHandlers.CompressHandler.CompressHandlerLevel.func4
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/compress.go:141
2023-10-18 00:01:30 sceneario_backend_vulcain   | net/http.HandlerFunc.ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /opt/hostedtoolcache/go/1.21.1/x64/src/net/http/server.go:2136
2023-10-18 00:01:30 sceneario_backend_vulcain   | github.com/gorilla/handlers.loggingHandler.ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/logging.go:47
2023-10-18 00:01:30 sceneario_backend_vulcain   | github.com/gorilla/handlers.recoveryHandler.ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /home/runner/go/pkg/mod/github.com/gorilla/handlers@v1.5.1/recovery.go:78
2023-10-18 00:01:30 sceneario_backend_vulcain   | net/http.serverHandler.ServeHTTP
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /opt/hostedtoolcache/go/1.21.1/x64/src/net/http/server.go:2938
2023-10-18 00:01:30 sceneario_backend_vulcain   | net/http.(*conn).serve
2023-10-18 00:01:30 sceneario_backend_vulcain   |       /opt/hostedtoolcache/go/1.21.1/x64/src/net/http/server.go:2009
2023-10-18 00:01:30 sceneario_backend_vulcain   | 172.18.0.2 - - [17/Oct/2023:22:01:30 +0000] "POST /uploads HTTP/1.1" 502 23 "https://sceneario-client.saas-production.loc/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0"