Open you-hengh opened 3 months ago
4.27.0
10.0.1
20.13.0
Windows
Windows 11 22631.3593
I noticed #97 and #98 , but they didn't solve the problem I encountered!
I used the routing module in the server, imported routes from other files, and used route prefixes
// server.js import fastify from 'fastify'; const server = fastify({ logger: { transport: { target: 'pino-pretty', options: { translateTime: 'SYS:HH:MM:ss', ignore: 'pid,hostname', }, }, }, }); server.register(import('@fastify/websocket')); server.register(import('./routes/index.js'), { prefix: '/restaurant' }); server.listen({ port: 3000, host: '127.0.0.1' }, (err, address) => { if (err) { server.log.error(err, address); process.exit(1); } });
Contents in './routes/index.js':
// ./routes/index.js import fastifyPlugin from 'fastify-plugin'; const router = async fastify => { fastify.get('/', { websocket: true }, (socket, req) => { socket.on('message', message => { socket.send('hi from server'); }); }); }; export default fastifyPlugin(router);
I used the link ws://localhost:3000/restaurant in the test software to not link to the server normally,
ws://localhost:3000/restaurant
But successfully linked to the server with ws://localhost:3000/
ws://localhost:3000/
No response
Make the link adhere to the route prefix, access the websocket through ws://localhost:3000/restaurant
Prerequisites
Fastify version
4.27.0
Plugin version
10.0.1
Node.js version
20.13.0
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
Windows 11 22631.3593
Description
I noticed #97 and #98 , but they didn't solve the problem I encountered!
I used the routing module in the server, imported routes from other files, and used route prefixes
Contents in './routes/index.js':
I used the link
ws://localhost:3000/restaurant
in the test software to not link to the server normally,But successfully linked to the server with
ws://localhost:3000/
Link to code that reproduces the bug
No response
Expected Behavior
Make the link adhere to the route prefix, access the websocket through
ws://localhost:3000/restaurant