Open
Description
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.28.1
Plugin version
6.0.7
Node.js version
20.9.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Arch
Description
Hello,
I'm having issues getting fastify-vite to run in production mode and from what I can tell it has to do with how fastify-static is setup.
Basically I have setup it very simply to grab all routes and return the client side application, this has worked fine in development mode but when I build and run it in production mode I get the below error.
I'm not sure if there is something I can do to fix this on my side, all the examples use "/" as the main route but that doesn't work properly for a client side application I want all routes (not already defined) to load the client side app. I saw this config referenced in another issue so I copied it from there.
await server.register(FastifyVite, {
root: import.meta.url,
dev: process.argv.includes('--dev'),
spa: true,
});
server.get('*', (req, reply) => {
return reply.html();
});
app-1 | /app/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/route.js:371
app-1 | throw new FST_ERR_DUPLICATED_ROUTE(opts.method, opts.url)
app-1 | ^
app-1 | FastifyError [Error]: Method 'HEAD' already declared for route '/*'
app-1 | at Object.addNewRoute (/app/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/route.js:371:19)
app-1 | at Object.route (/app/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/route.js:265:19)
app-1 | at Object.prepareRoute (/app/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/route.js:167:18)
app-1 | at Object._head [as head] (/app/node_modules/.pnpm/[email protected]/node_modules/fastify/fastify.js:265:34)
app-1 | at fastifyStatic (/app/node_modules/.pnpm/@[email protected]/node_modules/@fastify/static/index.js:120:15)
app-1 | at Plugin.exec (/app/node_modules/.pnpm/[email protected]/node_modules/avvio/lib/plugin.js:125:28)
app-1 | at Boot._loadPlugin (/app/node_modules/.pnpm/[email protected]/node_modules/avvio/boot.js:432:10)
app-1 | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
app-1 | code: 'FST_ERR_DUPLICATED_ROUTE',
app-1 | statusCode: 500
app-1 | }
Link to code that reproduces the bug
No response
Expected Behavior
Fastify starts normally