Welcome to the Linux Foundation Forum!

has Creating a Web Server with Fastify (7) chapter an error?

jhonny111s
jhonny111s Posts: 18
edited September 23 in LFW212 Class Forum

int his chapter we use "setNotFoundHandler" and it should return 405 and 404 but it does not return 404 but 200 (wrong status code) with a not found message.

that is my solution

fastify.setNotFoundHandler((request, reply) => {
    reply.status(404)  // ---> default Status error
    if (request.method !== 'GET') {
      reply.status(405)
      return 'Method Not Allowed\n'
    }
    return 'Not Found\n'
  })

Answers

Categories

Upcoming Training