8

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
}

I am using windows 10 with node v12.8.0 and fastify 2.8.0

painor
  • 1,119
  • 1
  • 8
  • 25

2 Answers2

10

The reason was that the URL was more than 100 characters which is the maximum for some reason.

it can be changed by using the maxparamlength. I also asked here and hopefully, the error will be changed in the future.

painor
  • 1,119
  • 1
  • 8
  • 25
1

You can use something like below to extend the max length for the path parameter in fastify:

import * as fastify from 'fastify';

fastify.default({
  maxParamLength: 1000,
});
Ethan
  • 876
  • 8
  • 18
  • 34