#URI parameters not passing from route to controller

35 messages · Page 1 of 1 (latest)

blazing flicker
#

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.

hollow juncoBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

prisma pumiceBOT
#

Project ID: 8a9f1a57-df4d-4cb9-9e39-8cbf6fecd716

blazing flicker
#

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

kindred laurel
#

are you using https when accessing your app?

blazing flicker
kindred laurel
#

???

blazing flicker
kindred laurel
#

can you show me the code for the route?

blazing flicker
#

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

kindred laurel
#

can you try logging the raw request url too?

blazing flicker
#

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?

kindred laurel
#

full url

blazing flicker
#

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

kindred laurel
#

whats with that underscore?

blazing flicker
#

this is the parameter value
app.route('/estabelecimentos/configuracoes/:estabelecimentoId/:slug/:value').post(
EstabelecimentosController.set_configuracao,
);

kindred laurel
blazing flicker
#

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

kindred laurel
#

can you log the raw request url for that endpoint and send it?

blazing flicker
#

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

kindred laurel
#

well you can see that your app is receiving the establishmentId param, it just isnt parsing it

blazing flicker
#

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

kindred laurel
#

this wouldn't really be a railway issue im afraid

blazing flicker
#

Running node server.js = Works
Running in AWS = Works
Running in Docker = Works
Running in Railway = not work

kindred laurel
#

as you can clearly see, your app does receive the path parameter

#

railway is not removing it

blazing flicker
#

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!

kindred laurel
#

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

blazing flicker
#

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.

kindred laurel
#

no worries at all, I hope you are able to get it sorted out