graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Redirect Behavior Unexpected Using Digital Ocean with Caddy

Open mwood23 opened this issue 6 years ago • 7 comments

Description

For my web app, I want to be able to create a reverse proxy and place all of Hasura behind api instead of the root of my domain (since that's where my app is served from). When I followed the docs, I couldn't get it to work from /api.

Recreation Steps

My Caddy config

my-domain.com {
    proxy /api graphql-engine:8080 {
        websocket
    }
}

Result {"path":"$","error":"resource does not exist","code":"not-found"}

After talking in the chat, all you have to do is add without /api after websocket leaving you this:

my-domain.com {
    proxy /api graphql-engine:8080 {
        websocket
        without /api
    }
}

This should give you access to the console at my-domain.com/api/console. However, if you go to my-domain.com/api, it redirects you to my-domain.com/console. If you add a trailing slash (my-domain.com/api), it redirects as expected.

mwood23 avatar Aug 17 '19 05:08 mwood23

This is a confirmed behaviour, which is not ideal.

We should issue the right redirect irrespective of the trailing slash.

shahidhk avatar Aug 21 '19 08:08 shahidhk

@marionschleifer Seems the task have been assigned multiple times to someone different but no updates ?

It seems this issue also affect Kubernetes when using an Ingress Controller and specifying we want Hasura on a specific path :

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /custom
        backend:
          serviceName: hasura
          servicePort: 8080

example.com/custom leads to {"path":"$","error":"resource does not exist","code":"not-found"}

I think it's overall in all cases we want Hasura on someting different from root /, that the issue happens.

Here is the error output of Hasura :

{
   "type": "http-log",
   "timestamp": "2020-07-20T21:57:04.445+0000",
   "level": "error",
   "detail": {
      "operation": {
         "error": {
            "path": "$",
            "error": "resource does not exist",
            "code": "not-found"
         },
         "request_id": "a4544567-b2db-4b6f-bc70-82dd1ee7b31d",
         "response_size": 65,
         "raw_query": ""
      },
      "http_info": {
         "status": 404,
         "http_version": "HTTP/1.1",
         "url": "/custom",
         "ip": "X.X.X.X",
         "method": "GET",
         "content_encoding": null
      }
   }
}

kevinmarrec avatar Jul 20 '20 21:07 kevinmarrec

Me too! I'd like to have Hasura live under a different URL path as well. Although, to be honest, I know this is something quite specific and I'd totally understand if this feature is never implemented.

Here's my scenario:

  • Reverse proxy (e.g. api gateway) points customdomain.com/console to hasura/
  • Going to customdomain.com/console gets me an infinite redirect
  • Going to customdomain.com/console/ gets me to customdomain.com/console/console (and shows the console)
  • Going to customdomain.com/console/ takes me tocustomdomain.com/console/console (and shows the console)
  • The console, when displayed, isn't working because the console is pointing GraphiQL to customdomain.com/console/v1/graphql (but it should be pointing to customdomain.com/console/console/v1/graphql).

The specific scenario above is irrelevant. What matters is that it would be solved by having a server flag that tells Hasura under which url path it is being served. Anyway, the solution specific to AWS API Gateway is to use route type http instead of http_proxy—my immediate problem is solved. May this help someone.

gunar avatar Aug 14 '20 14:08 gunar

I would like to know if there any solutions to this?

jkaliaSignify avatar Jun 02 '21 22:06 jkaliaSignify

@kevinmarrec did you figure anything out to get this working? please guide 😄

jkaliaSignify avatar Jun 02 '21 22:06 jkaliaSignify

Dunno about caddy but in nginx ingress we have to use regex for path re-writes

sample yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: testops
  labels:
    name: testops
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: "/$1"
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: testops.com
    http:
      paths:
      - pathType: Prefix
        path: /address/(.+)
        backend:
          service:
            name: graphql-engine
            port: 
              number: 9000        

jkaliaSignify avatar Jun 03 '21 16:06 jkaliaSignify

Can confirm that this occurs with envoy gateway. Hasura is accessible via https://example.org/hasura, but when visiting that exact URL I get redirected to https://example.org/console, when I expect to get redirected to https://example.org/hasura/console. If I add the trailing slash to the original URL (to get https://example.org/hasura/), the redirect works as expected.

cnemo-cenic avatar Jan 29 '25 19:01 cnemo-cenic