diff --git a/packages/server/packages/play-node-go/server/bin/www b/packages/server/packages/play-node-go/server/bin/www index ec05bde..51aceb3 100755 --- a/packages/server/packages/play-node-go/server/bin/www +++ b/packages/server/packages/play-node-go/server/bin/www @@ -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)); diff --git a/packages/server/packages/play-node-go/server/server.js b/packages/server/packages/play-node-go/server/server.js index cffaf59..81fc4da 100644 --- a/packages/server/packages/play-node-go/server/server.js +++ b/packages/server/packages/play-node-go/server/server.js @@ -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 })); diff --git a/packages/server/packages/play-node-go/server/socket.js b/packages/server/packages/play-node-go/server/socket.js new file mode 100644 index 0000000..0ad49fc --- /dev/null +++ b/packages/server/packages/play-node-go/server/socket.js @@ -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; + } +} \ No newline at end of file