You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As mentioned in the title, does express-ws support HTTP2?
I have successfully docked data using the WSS protocol, but I still want to be able to use HTTP2.
This is my app.js:
importexpressfrom'express'importexpressWsfrom'express-ws'importpathfrom'node:path'importhttpsfrom'node:https'// import http2 from 'node:http2'importfsfrom'fs-extra'importrouterfrom'./routers/index.js'constapp=express()// Read SSL certificates and private keysconstoptions={key: fs.readFileSync('/***/***.key'),cert: fs.readFileSync('/***/***.pem'),}consthttpsServer=https.createServer(options)// const httpsServer = http2.createSecureServer(options) // Building a link using HTTP2 failed for unknown reasons//Mixing the WebSocket service into the app is equivalent to adding a .ws method to the appexpressWs(app,httpsServer)app.use(express.json())app.use(express.urlencoded({extended: true}))app.use(express.static(path.join(import.meta.dirname,'public')))// Using the Routing Moduleapp.use('/api',router)// app.listen(3000, () => {// console.log('Service started: http://localhost:3000')// })// Start the HTTP/2 server and listen on the porthttpsServer.on('request',app)httpsServer.listen(3000,()=>{console.log('Service started: https://localhost:3000')})
This is my router file:
importexpressfrom'express'import{nanoid}from'nanoid'importexpressWsfrom'express-ws'// Express-ws must be introduced again, otherwise an error will be reported. The router has no ws method.import{getMenu,getName}from'../utils/index.js'constrouter=express.Router()expressWs(router)//I don't quite understand why this step is repeated, but with it the program works fine// Create ws link, share menu statusrouter.ws('/:tableID',(ws,req)=>{// After the first link, provide the menu content and usernamews.on('message',msg=>{constmessage=JSON.parse(msg)if(message.type==='getName'){ws.send(JSON.stringify({menu: getMenu(),tableID: req.params.tableID,username: getName(),orderID: nanoid(),}))}else{ws.send('Send message format error')}})})exportdefaultrouter
The above is the basic content of my websocket. If you need more detailed instructions, you can leave a message here. I expect to be able to use HTTP2. Its function further reduces network overhead and is a very good protocol
The text was updated successfully, but these errors were encountered:
As mentioned in the title, does express-ws support HTTP2?
I have successfully docked data using the WSS protocol, but I still want to be able to use HTTP2.
This is my app.js:
This is my router file:
The above is the basic content of my websocket. If you need more detailed instructions, you can leave a message here. I expect to be able to use HTTP2. Its function further reduces network overhead and is a very good protocol
The text was updated successfully, but these errors were encountered: