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

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

Open
zAlweNy26 opened this issue Oct 25, 2022 · 2 comments
Open

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

zAlweNy26 opened this issue Oct 25, 2022 · 2 comments

Comments

@zAlweNy26
Copy link

zAlweNy26 commented Oct 25, 2022

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) {

@matthewp
Copy link
Owner

Sorry about this, I'll take a look. It's possible there are multiple * routes. We can probably do this another way.

@MBing
Copy link

MBing commented Dec 19, 2023

I am running into the same issue with Astro 3.5.4.
I also tried this: https://docs.astro.build/en/guides/integrations-guide/node/#middleware
but then my client was only showing the static files (like robots.txt and manifest.json).

When using this adapter I am able to get the actual components & pages running, but I am having issues with the static files. That's why I wanted to use fastify.register(..) and also when using fastify.register(cors) I get this same error.

I assume that when using the register it will go automatically to all routes and then has a conflict because this was set before as shown above.

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

3 participants