Rewriting with URL parameters in NodeJS

On a NodeJS server model project, I setup an App query parameter:

This parameter is used as an input parameter in a server action to query and bind dynamic data to the page.

Navigating to the path?[user_id]=[id] (path?id=21 i.e.) works fine and shows correct data, filtered by the query parameter. The server action in the console under XHR is named get_user?id=21 then.

Although I also setup routing rules for the same parameter, navigating to path/[id] results in a status 500 error in the console for the server action named get_user in XHR:

Undefined binding(s) detected when compiling FIRST. Undefined column(s): [users.id] query: select * from "users" where "users"."id" = ? limit ?"

These are my routing rules:

image

Am I missing something here or doing something wrong?

Any thoughts on this @Teodor? Is this a bug?

I checked the issue and there seems to be an issue with URL params and URL rewrite with NodeJS.
@patrick will check this, after our summer break.

1 Like

Okay thanks for looking into it Teodor.

Hope bugs like these can be solved soon after the summer break.
I am sure you agree that some of them (like this one and others like the csv import bug) are quite critical functionalities for many Wappler user’s projects. Looking forward to the first update after the summer break!

Was there a meta tag added to the code after you created the route?

Should look like:

<meta name="ac:route" content="/profile/:user_id">

If it is missing then you could add it under the Wappler include comment in profile.ejs.

Let me know if that fixes the problem.

1 Like

I tried Patrick, and it didn’t solve the problem unfortunately. Also played with the Meta inspector settings a bit:
image

I resaved/regenerated the routing rules, re-deployed and restarted al services and tested several times, however all without success unfortunately.

Was there a meta tag in the code? It should be generated when creating a route.

When missing add it in code view on the content page (not on the layout page). Important is that the name is ac:route and the content is the path as defined in your route.

If the meta tag is missing then the route is not being parsed on the page and the parameters will not be available.

I think it is just that the meta tag is not being generated that causes the problem, we will investigate that and fix it.

Hi Patrick,

There was no meta tag in the code, so it wasn’t generated when creating the route I suppose.
Adding the meta tag manually in the content page didn’t solve the issue either, unfortunately. I am sure I entered “ac:route” as the meta tag name and the exact path from the routing rule as the content value:
<meta name="ac:route" content="/profile/:user_id">

Removing and adding the routing rule again didn’t fix the issue and the meta tag was indeed not automatically added to the content page’s code.

Hi @patrick,

FYI: I had another setup whit other data, parameters and pages where I tried to setup the routing. Unfortunately with the same result:

  1. The routing meta tag is not inserted on the content page.
  2. While the url parameters work fine, the routed urls don’t (/path/:parameter).

Let me know if you need more information. Thanks.

Hi @patrick,

I finally got it working:

  1. Added the meta tag manually.
  2. Used the query.[parameter] instead of the query-manager.data.[paramater] (Sorry for this rookie mistake… :see_no_evil::upside_down_face:)

However it works now I am wondering why one would use a query manager on the page if the app’s query parameter can be used for routing?

Thanks for your help!

Query manager is only required when you want to change a query param value.
If you just want to read the value, you don’t need to add query manager on the page. You can just use the values returned under query.

1 Like

I see, thanks for clearing that up Teodor! :slight_smile::+1:

This has been fixed in Wappler 3.1

1 Like

This topic was automatically closed after 47 hours. New replies are no longer allowed.