Skip to content

Method 'OPTIONS' already declared for route '*' #9

@zAlweNy26

Description

@zAlweNy26

Sorry if this is not the right place to post this, but I don't know what else this error might refer to, I already tried asking the fastify community on Discord.

I get this error when registering the plugin @fastify/cors :

node_modules\fastify\lib\route.js:306
            throw new FST_ERR_DUPLICATED_ROUTE(opts.method, opts.url)
            ^
FastifyError [Error]: Method 'OPTIONS' already declared for route '*'
    at Object.addNewRoute (...\node_modules\fastify\lib\route.js:306:19)
    at Object.route (...\node_modules\fastify\lib\route.js:217:19)
    at Object.prepareRoute (...\node_modules\fastify\lib\route.js:150:18)
    at Object._options [as options] (...\node_modules\fastify\fastify.js:264:34)
    at fastifyCors (...\node_modules\@fastify\cors\index.js:42:11)
    at Plugin.exec (...\node_modules\avvio\plugin.js:130:19)
    at Boot.loadPlugin (...node_modules\avvio\plugin.js:272:10)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'FST_ERR_DUPLICATED_ROUTE',
  statusCode: 500
}

The problem is that I didn't register the route '*' so I don't know how to fix that.

Edit:
I found these pieces of code in your adapter, I think they are causing the error (?)

fastify.all('/*', function (request) {
and this
fastify.all('/*', async function (request, reply) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions