URI parameters not passing from route to controller
I have a nodejs application that has the following URL
/establishment/:id/:slug
The :id parameter and the :slug parameter don't arrive in the controller, if I use a req.params the return is an empty object.
I believe that the route is not passing the parameter to the controller, but the funny part is that this problem is only happening on the railway.
I have this same application on AWS with exactly the same files and it works normally there.
28 Replies
Project ID:
8a9f1a57-df4d-4cb9-9e39-8cbf6fecd716
Project ID 8a9f1a57-df4d-4cb9-9e39-8cbf6fecd716
Note: all urls that have a parameter in the URL are not working
The application falls on the right route, but cannot access the URL parameters
are you using https when accessing your app?
???
Yes, using https in the front end and back-end
https://homologacao.zspay.com.br/. Front end
https://z-api-release.up.railway.app/ Back end
can you show me the code for the route?
Yes, one moment
Route:
app.route('/estabelecimentos/configuracoes/:estabelecimentoId/:slug/:value').post(
EstabelecimentosController.set_configuracao,
);
Controller:
exports.set_configuracao = async (req, res) => {
const transaction = await EstabelecimentoConfiguracao.sequelize.transaction();
try {
const { estabelecimentoId, slug, value } = req.params;
console.log(estabelecimentoId, slug, value)
console.log(req.params)
return res.json({ success: true, result }); } catch (error) { console.log(error); await transaction.rollback(); return res.status(202).json({ success: false, error: error.message }); } }; All variables estabelecimentoId, slug, value is empty The console.log(req.params) is empty
return res.json({ success: true, result }); } catch (error) { console.log(error); await transaction.rollback(); return res.status(202).json({ success: false, error: error.message }); } }; All variables estabelecimentoId, slug, value is empty The console.log(req.params) is empty
can you try logging the raw request url too?
When you say to get the raw request, are you referring to the parameters that are arriving inside the req or the url in full with the parameters?
full url
Request URL: https://z-api-release.up.railway.app/estabelecimentos/configuracoes/158/logo/_
Request headers
:authority: z-api-release.up.railway.app
:method: POST
:path: /estabelecimentos/configuracoes/158/logo/_
:scheme: https
accept: application/json, text/plain, /
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.6
access-control-allow-origin: *
authorization: Bearer bearerToken
content-length: 8990
content-type: multipart/form-data; boundary=----WebKitFormBoundarymdC7w2biL7Xh7GpD
origin: https://homologacao.zspay.com.br
referer: https://homologacao.zspay.com.br/
sec-ch-ua: "Chromium";v="112", "Brave";v="112", "Not:A-Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
sec-gpc: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Response Headers:
access-control-allow-origin: *
content-length: 1056
content-security-policy: default-src 'none'
content-type: text/html; charset=utf-8
date: Tue, 30 May 2023 17:59:43 GMT
server: railway
x-content-type-options: nosniff
x-powered-by: Express
x-request-id: f109727a-26f9-4f08-b7cd-ea837311df44
whats with that underscore?
this is the parameter value
app.route('/estabelecimentos/configuracoes/:estabelecimentoId/:slug/:value').post(
EstabelecimentosController.set_configuracao,
);
why is there an underscore at the end of the paths
I didn't make this end point, actually I don't think it's serving anything....
But to make it easier, this url:
https://z-api-release.up.railway.app/estabelecimentos/15057
it doesn't have _ and it doesn't work either, it can't capture the parameter 15057
this route is:
app.route('/establishments/:establishmentId')
.put(passport.authenticate('bearer', { session: false }), ZoopController.edit_establishment);
no parameter in any url works
Query string, works ok
can you log the raw request url for that endpoint and send it?
Request URL: https://z-api-release.up.railway.app/estabelecimentos/15057
Request Method: GET
Status Code: 202
Remote Address: 104.196.232.237:443
Referrer Policy: strict-origin-when-cross-origin
Request URL: https://z-api-release.up.railway.app/estabelecimentos/15057
Request Method: GET
Status Code: 202
Remote Address: 104.196.232.237:443
Referrer Policy: strict-origin-when-cross-origin
:authority: z-api-release.up.railway.app
:method: GET
:path: /estabelecimentos/15057
:scheme: https
accept: application/json, text/plain, /
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.6
authorization: Bearer TokenBearer
origin: https://homologacao.zspay.com.br
referer: https://homologacao.zspay.com.br/
sec-ch-ua: "Chromium";v="112", "Brave";v="112", "Not:A-Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
sec-gpc: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36
Response headers
access-control-allow-origin: *
content-length: 88
content-type: application/json; charset=utf-8
date: Tue, 30 May 2023 18:53:27 GMT
etag: W/"58-3AbN97aGztNX5o55rOE3qWU6GxM"
server: railway
x-powered-by: Express
x-request-id: d74f07ec-a1f0-442c-ab0c-c56d13aa1952
well you can see that your app is receiving the establishmentId param, it just isnt parsing it
I just tested if it was a problem with the docker image, but running the image locally all works fine....
Only on the railway is this problem
this wouldn't really be a railway issue im afraid
Running node server.js = Works
Running in AWS = Works
Running in Docker = Works
Running in Railway = not work
as you can clearly see, your app does receive the path parameter
railway is not removing it
I understand...
but the app receives the parameter, sends it to the right route, when the route sends it to the controller, the parameter disappears...
A few days ago it was working fine and suddenly it stopped...
But that's ok, thanks for the help!
i agree its super odd, but its just not caused by railway
i wish i could tell you what in your code is causing it, but i simply dont know
I'm researching this problem, and after simplifying my routes a lot, I saw that there really is something in the application that is causing this....
Thanks for the help and sorry for the inconvenience.
no worries at all, I hope you are able to get it sorted out
might be some middleware somewhere that's fattening the incoming url