connect socket

This commit is contained in:
Sorrel Bri 2020-01-07 23:17:10 -08:00 committed by sorrelbri
parent c14a76e996
commit 6171fa85c5
3 changed files with 22 additions and 0 deletions

View file

@ -88,3 +88,7 @@ function onListening() {
: 'port ' + addr.port; : 'port ' + addr.port;
debug('Listening on ' + bind); debug('Listening on ' + bind);
} }
const socketIO = require('socket.io')
const socket = require('../socket').socket;
const io = socket(socketIO(server));

View file

@ -2,6 +2,9 @@ const createError = require('http-errors');
const express = require('express'); const express = require('express');
const cors = require('cors'); const cors = require('cors');
const socketIO = require("socket.io");
const http = require('http');
const path = require('path'); const path = require('path');
const cookieParser = require('cookie-parser'); const cookieParser = require('cookie-parser');
const logger = require('morgan'); const logger = require('morgan');
@ -15,14 +18,19 @@ const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users'); const usersRouter = require('./routes/users');
const app = express(); const app = express();
const server = require('./bin/www');
const corsOptions = { const corsOptions = {
origin: process.env.REACT_ADDRESS origin: process.env.REACT_ADDRESS
} }
const port = process.env.PORT;
app.options('*', cors(corsOptions)); app.options('*', cors(corsOptions));
app.use('*', cors(corsOptions)); app.use('*', cors(corsOptions));
app.use(logger('dev')); app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: false })); app.use(express.urlencoded({ extended: false }));

View 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;
}
}