connect socket
This commit is contained in:
parent
c18951b838
commit
bdefc1d070
3 changed files with 22 additions and 0 deletions
|
@ -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));
|
||||||
|
|
|
@ -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 }));
|
||||||
|
|
10
server/socket.js
Normal file
10
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