使用這玩意,如果是前端請(qǐng)求的是ws連接按咒,使用ip+端口,是可用的姥敛,
但是wss不行道逗,怎么解決呢兵罢?
const fs = require('fs')
let options = {
? key: fs.readFileSync('./ssl/a.key', 'utf8'),
? cert: fs.readFileSync('./ssl/b.crt', 'utf8')
}
const Koa = require('koa')
const websockify = require('koa-websocket')
const app = websockify(new Koa(), {}, options)
然后,別用require('https')這個(gè)滓窍,
直接app.listen(443)即可卖词,因?yàn)檫@個(gè)中間件已經(jīng)弄好了相關(guān)配置(官方說的)
The WebSocket options object just get passed right through to the?new WebSocketServer(options)?call.
The optional HTTPS options object gets passed right into?https.createServer(options). If the HTTPS options are passed in, koa-websocket will use the built-in Node HTTPS server to provide support for the?wss://?protocol.