Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router not working with specific url. #103

Closed
painor opened this issue Sep 11, 2019 · 7 comments
Closed

Router not working with specific url. #103

painor opened this issue Sep 11, 2019 · 7 comments

Comments

@painor
Copy link

painor commented Sep 11, 2019

I have this router in my code

fastify.get('/:link', (req, reply) => {
    req.params.url = req.host+req.url;
    reply.view("template.ejs",req.params);

});

I am trying to catch URLs and handle them in the template. The URLs are all encodeURIComponent escaped. for some reason, some URLs would return a 404 not found and I am not sure why.
This is the link that worked.

http://127.0.0.1:3000/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fe%2Fee%2FChain_link_icon.png

and this is the one that didn't work.

http://127.0.0.1:3000/https%3A%2F%2Fs7386.pcdn.co%2Fwp-content%2Fuploads%2F2016%2F07%2Fadd-on-direct-link-tracking-771x386.png

the error is


{
"message": "Route GET:/https%3A%2F%2Fs7386.pcdn.co%2Fwp-content%2Fuploads%2F2016%2F07%2Fadd-on-direct-link-tracking-771x386.png not found",
"error": "Not Found",
"statusCode": 404
}

using windows 10
node v12.8.0
fastify 2.8.0

@RafaelGSS
Copy link
Member

You can try receive the link by query params and passing:

youdomain/link?url=https://example.com/img.jpg and use regexp inside schema to get only pictures.

@Eomm
Copy link
Member

Eomm commented Sep 11, 2019

@RafaelGSS that is a nicer solution 👍

Anyway, the problem here is the length of the path parameter that is 100 char

Here the details: https://github.com/delvedor/find-my-way

You can set a custom length for parameters in parametric (standard, regex and multi) routes by using maxParamLength option, the default value is 100 characters.
If the maximum length limit is reached, the default route will be invoked.

@StarpTech
Copy link
Member

StarpTech commented Sep 11, 2019

@Eomm only 100 chars seems odd to me. We should change that default in fastify and a clean error should be logged.

@Eomm
Copy link
Member

Eomm commented Sep 11, 2019

You can already set it up
https://github.com/fastify/fastify/blob/master/docs/Server.md#maxparamlength
I should have pointed it out to @painor

Maybe to throws an error we should check the routing lib

@painor
Copy link
Author

painor commented Sep 11, 2019

Oh thanks. I tried debugging but it tricked me because when I removed the .png it worked so I thought maybe it was the extension and was debugging that for hours lol.

@painor painor closed this as completed Sep 11, 2019
@StarpTech
Copy link
Member

@Eomm nevermind this only effects the "path" 😄

@kireerik
Copy link

#103 (comment)

@StarpTech I highly agree. I recommend we open this issue and resolve it accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants