Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Express quick start example fails due to incorrect whoami request port

Abierto
#767 15 comentarios 0 reacciones 1 asignado Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug
Preflight checklist
Describe the bug

https://www.ory.sh/docs/guides/protect-page-login/expressjs#require-login-to-access-the-home-page

.toSession seems to want to make a call to /.ory/.../whoami through the proxy. However i think axios wants to make this call at localhost port 80, leading to the following error

[0] Error: connect ECONNREFUSED ::1:80
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
[0]   errno: -61,
[0]   code: 'ECONNREFUSED',
[0]   syscall: 'connect',
[0]   address: '::1',
[0]   port: 80,
[0]   config: {
[0]     url: '/.ory/sessions/whoami',
[0]     method: 'get',
[0]     headers: {
[0]       Accept: 'application/json, text/plain, */*',
[0]       Cookie: '__cflb=0pg1QYeUHkKyPHC72r3PJ1fj2WK6WMwzqHhgHXum; csrf_token_a5d02dd42b4ef065bbbd5ed674b19b5d2e6dc4f2a3e4acc8684f15ae24c19b97=JGnPuz6b+Jqy10PCRqwvR2dgrw2UXJ1K96SHlDCWSag=; ory_session_greatgoldwasserlbe7q6kfiv=MTY1MDMwMTk3MnxnSmhfWkRBM2lSVkJwX1JpY0oyYUpGV21lbm9jel9PWkl0a2RwVzJ0eGRJT1lLSm9JMlZUUjZyc0xYalJyMS1naC0zS2FleWxaM0lsT0pxMjNSRkRGQVlTbjU2ZUtaYTAxVEQ4MWxoZUlfcFR6Rml3YkM4bE1XdmVQQms3SjhZR0NaQ2UwMklqcXc9PXygWBBkEKzVhZUiBc1uzDEO0KmKCRdEUET-qIkFgs5LkQ==',

So we need to tell axios it should match the port we used when we started the proxy

"dev:proxy": "ory proxy --no-jwt --port 8000 http://localhost:8001/"

some solutions at the doc level

  1. insist we pass a proxy to axios in development environments
.toSession(undefined, req.header('cookie'), {
    proxy: {
        host: 'localhost',
        port: 8000
    }
})
  1. in development make sure we pass the full base path inclusive of port
const ory = new orySDK.V0alpha2Api(
    new orySDK.Configuration(
        // @ts-ignore
        {basePath: 'http://localhost:8000/.ory',
            baseOptions: {
                withCredentials: true
            }
        }
    )
)

These both work and i am also wondering

  1. if there is a way to detect if we are proxying and on what port so this could be done automatically somehow
  2. perhaps having this as an envar like the sdk url

https://github.com/ory/docs/blob/master/code-examples/protect-page-login/expressjs/routes/index.js

Reproducing the bug
  1. follow example on https://www.ory.sh/docs/guides/protect-page-login/expressjs
  2. register a user
  3. observe redirect loop once user registered due to failing whoami request
Relevant log output

No response

Relevant configuration

No response

Version

"@ory/client": "^0.0.1-alpha.167"

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Ory Cloud

Additional Context

No response

Lenguaje dominante
TypeScript
Estrellas
161
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ory/docs

Todos los issues de ory/docs

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.