так в nuxt подключаю плагин
plugins: [
{ src: '~/plugins/socket.io.js', ssr: false }
],
в консоль летят ошибки:
vendors.app.js:2332 GET localhost:3000/socket.io/?EIO=3&transport=polling&... 404 (OK)
Когда плагин так подключаю всё равно не пашет:
// plugins/socket.io.js
import Vue from 'vue';
import io from 'socket.io-client';
import VueSocketIOExt from 'vue-socket.io-extended';
const socket = io('http://localhost:3000');
export default ({ store }) => {
Vue.use(VueSocketIOExt, socket, { store });
}
servet.js
import Koa from 'koa'
import { Nuxt, Builder } from 'nuxt'
import * as _io from 'socket.io'
import http from 'http'
import rootRouter from './routes'
const app = new Koa(),
host = process.env.HOST || '127.0.0.1',
port = process.env.PORT || 3000,
server = http.createServer(app.callback()),
io = _io(server)
io.on('connection', socket => {
console.log('io Connected')
socket.emit('newMessage', {
text: 'WHAT'
})
})
var start = async function() {
const config = require('../nuxt.config.js')
config.dev = !(app.env === 'production')
const nuxt = new Nuxt(config)
if (config.dev) {
const builder = new Builder(nuxt)
await builder.build()
}
app.use(rootRouter.routes()).use(ctx => {
ctx.status = 200
ctx.respond = false
ctx.req.ctx = ctx
nuxt.render(ctx.req, ctx.res)
})
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port)
}
start()