Hello. Trying to test a NestJS setup of Ory Cloud....
# ory-network
d
Hello. Trying to test a NestJS setup of Ory Cloud. Set up with the Ory Proxy in front. I do a config like this:
Copy code
const kratos = new V0alpha2Api(
      new Configuration({
        basePath: '.ory',
      }),
    );

return kratos
      .toSession(undefined, request.header('Cookie'))
      .then(({ data: session }) => {
        console.log(session);
        return true;
      })
      .catch((err) => {
        console.error(err);
        return false;
      });
(Even though the ExpressJS documentation uses
baseUrl
not
basePath
-- I think it's wrong?) And then I can debug and see it always gets caught with an error in
toSession()
. The error is always ECONNREFUSED to 127.0.0.1:80, seemingly hitting the URL
.ory/sessions/whoami
. One of the properties of the
err.request
objects is
_currentUrl
which is pointing to
"http:.ory/sessions/whoami"
and I'm sure... that's... not right. But it's not clear why this is wrong. Am I missing something in config? 🤔
p
Hi @User Is your browser pointing to the proxy url?
also are you running anything in front of the proxy, like Caddy?
d
@User Sorry for the slow reply. I AM pointing to the proxy URL, with nothing in front.
Whether I've configured the proxy correctly -- I don't know! 🙂 I think I have; I just set up the
ORY_SDK_URL
environment variable before I run it.
p
Hi @User Assuming your application is on
localhost:3000
the proxy would be
ory proxy <http://localhost:3000>
with the
ORY_SDK_URL
pointing to your project URL. Maybe try set the base url
/.ory
with the forward slash like with the expressJS example https://www.ory.sh/docs/guides/protect-page-login/expressjs#require-login-to-access-the-home-page
d
Thanks @User I'll futz with it right now. I actually had the leading forward slash and removed it wondering if that was the issue.
(And yep,
localhost:3000
)
@User Yeah so I had my proxy command set up (from following some documentation somewhere) as an NPM script:
Copy code
ory proxy --no-jwt --port 4000 <http://localhost:3000/>
But I used the one as you wrote it, and I re-added the forward slash. Same deal though.
p
try set the baseURL then of the proxy URL
d
So I actually just hardcoded a full basePath...
Copy code
const kratos = new V0alpha2Api(
      new Configuration({
        basePath: '<http://localhost:4000/.ory>',
      }),
    );
ha like that ^ you mean, right?
...That actually worked.
p
yes 👍 😆
NestJS probably doesn't pass along the origin for some reason like ExpressJS does.
d
oooooo
That is great to know.
Well you've done it again.
..Presumably. This is my first time interacting with you.
But you've got a 100% success rate for me, so congrats.
Thank you so much.
p
haha thank you 🙏
❤️ 1