connect socket
This commit is contained in:
parent
90e078fa86
commit
395e2b1d86
3 changed files with 22 additions and 0 deletions
|
@ -88,3 +88,7 @@ function onListening() {
|
|||
: 'port ' + addr.port;
|
||||
debug('Listening on ' + bind);
|
||||
}
|
||||
|
||||
const socketIO = require('socket.io')
|
||||
const socket = require('../socket').socket;
|
||||
const io = socket(socketIO(server));
|
||||
|
|
|
@ -2,6 +2,9 @@ const createError = require('http-errors');
|
|||
const express = require('express');
|
||||
|
||||
const cors = require('cors');
|
||||
const socketIO = require("socket.io");
|
||||
const http = require('http');
|
||||
|
||||
const path = require('path');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const logger = require('morgan');
|
||||
|
@ -15,14 +18,19 @@ const indexRouter = require('./routes/index');
|
|||
const usersRouter = require('./routes/users');
|
||||
|
||||
const app = express();
|
||||
const server = require('./bin/www');
|
||||
|
||||
|
||||
const corsOptions = {
|
||||
origin: process.env.REACT_ADDRESS
|
||||
}
|
||||
const port = process.env.PORT;
|
||||
|
||||
|
||||
app.options('*', cors(corsOptions));
|
||||
app.use('*', cors(corsOptions));
|
||||
|
||||
|
||||
app.use(logger('dev'));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
|
|
10
packages/server/server/socket.js
Normal file
10
packages/server/server/socket.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
socket: io => {
|
||||
io.on('connection', () => console.log('connected'))
|
||||
io.on('connect', ()=> {
|
||||
console.log('connected');
|
||||
io.emit('connected', {message: 'socket connected'});
|
||||
})
|
||||
return io;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue