How to get URL of current page in NodeJS

This is what I have done so far

But this gives me the URL of the API file.

The actual aim of my effort is to get just the pathname for the current page as in /about so that I can use it to filter the database.

What am I doing wrong?

That would be stored in $_PARAM as long as it’s defined in the route

Thanks for replying, much appreciated.

This is the routing:

image

There are no URL parameters, just straight routes.

What if you output just {{$_SERVER}}?
To see what you get.

How about PATH_INFO? I think you need to print the server variable from the page and use get to pass the value to your API.

Actually Ben…is the SC being called from the page itself or are you testing the SC?

image

$_SERVER.URL is the right variable as long you are calling the SC from the frontend. If not it will show you the api url.

Have a look at app.js where the PHP syntax has been converted into NodeJS

These are the instructions that are currently available.

Edit: PATH_INFO gives the same result:

image

I am working on getting server side data to populate the meta tags. I know that you have been querying this as well.

Actually I’ve tested it. Indeed, both URL and PATH_INFO will return the URL of the API if you directly call it from Server Connect API. Try out REMOTE_ADDR and see if it returns the address of the server or client.

Returns 127.0.0.1

What code are you running on the page for that test?

Just filter it using GET variable from your page, for example dmx-param:url="<%=_('$_SERVER.URL')%>"

This is the address of localhost. I'm not sure how server variables work in Node.js but these vars are not native to Node.js, but were added by the team if I'm not mistaken as I've read it somewhere. Perhaps @JonL can add you seem to know better about this topic.

Thanks for putting up with my problem.

I do not need the code on the client, I need the code to filter the database.

To explain better, I followed

https://docsdev.wappler.io/guides/sever-side-rendering-with-nodejs which works well for the first record in the database. I need to filter the info in respect to the page (or URL) that was chosen.

Okay, on client side we can just use browser extension the get the url though.

Yes, it shows in app.js

What’s is the code in the page that you are running your test from? And how is the route defined in routes.js for /about??

image

The only logical address that you can get using server variable as I understand is by asking for referrer i.e. HTTP_REFERER

:+1:

I’ll see if I can work with that. Great find, thank you.