Skip to content

hasRoute not working properly #5503

@ritikrao1

Description

@ritikrao1

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.26.2

Plugin version

No response

Node.js version

14.18.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.3

Description

hasRoute is giving me false where as the route with same http method and url exists

reproduce from here

const app = fastify({logger: true, caseSensitive: false});
app.register(function (app,options, done){
    app.route({
        method: "POST",
        url : '/delivery-service/cancellation/getpafcancellationdetails', 
        handler: async (req, res) => {
            console.log("in api handler")
            req.result = { msg: "sent successfully"};
            res.status(200).send(req.result);
        }
    });
    done();
})



app.register(function (app, options ,done){
    app.hasRoute({ method: "post", url: "/delivery-service/cancellation/getpafcancellationdetails"})? null :
    app.route({
        method: "POST",
        url : '/delivery-service/cancellation/getpafcancellationdetails', 
        handler: async (req, res) => {
            console.log("in api handler")
            req.result = { msg: "sent successfully"};
            res.status(200).send(req.result);
        }
    });
    done();
})

app.addHook('onReady', (done) => {
    console.log("Service running on port: 3000");
    done();
});
app.listen({host: 'localhost', port: 3000});

Link to code that reproduces the bug

No response

Expected Behavior

hasRoute should return true in when i call it in second app register, as the api with that url and method exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions