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
Percy
Percy2y ago
Project ID: 8a9f1a57-df4d-4cb9-9e39-8cbf6fecd716
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
are you using https when accessing your app?
Brody
Brody2y ago
???
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
can you show me the code for the route?
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
can you try logging the raw request url too?
Dayglor
DayglorOP2y ago
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?
Brody
Brody2y ago
full url
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
whats with that underscore?
Dayglor
DayglorOP2y ago
this is the parameter value app.route('/estabelecimentos/configuracoes/:estabelecimentoId/:slug/:value').post( EstabelecimentosController.set_configuracao, );
Brody
Brody2y ago
why is there an underscore at the end of the paths
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
can you log the raw request url for that endpoint and send it?
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
well you can see that your app is receiving the establishmentId param, it just isnt parsing it
Dayglor
DayglorOP2y ago
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
Brody
Brody2y ago
this wouldn't really be a railway issue im afraid
Dayglor
DayglorOP2y ago
Running node server.js = Works Running in AWS = Works Running in Docker = Works Running in Railway = not work
Brody
Brody2y ago
as you can clearly see, your app does receive the path parameter
Brody
Brody2y ago
railway is not removing it
Dayglor
DayglorOP2y ago
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!
Brody
Brody2y ago
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
Dayglor
DayglorOP2y ago
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.
Brody
Brody2y ago
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
Want results from more Discord servers?
Add your server