From 9f0875f48328f34595442134b34c8e7aba3af46b Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Wed, 8 Jan 2020 11:24:24 -0800 Subject: [PATCH] stub middleware (including socket), controllers architecture --- packages/server/server/bin/www | 4 ++-- packages/server/server/controllers/auth.js | 0 packages/server/server/controllers/index.js | 0 packages/server/server/routes/api.js | 0 packages/server/server/routes/auth.js | 0 packages/server/server/server.js | 6 ------ packages/server/server/socket.js | 10 +++++++--- 7 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 packages/server/server/controllers/auth.js create mode 100644 packages/server/server/controllers/index.js create mode 100644 packages/server/server/routes/api.js create mode 100644 packages/server/server/routes/auth.js diff --git a/packages/server/server/bin/www b/packages/server/server/bin/www index 51aceb3..9400248 100755 --- a/packages/server/server/bin/www +++ b/packages/server/server/bin/www @@ -90,5 +90,5 @@ function onListening() { } const socketIO = require('socket.io') -const socket = require('../socket').socket; -const io = socket(socketIO(server)); +const enableSocket = require('../socket').enableSocket; +const io = enableSocket(socketIO(server)); diff --git a/packages/server/server/controllers/auth.js b/packages/server/server/controllers/auth.js new file mode 100644 index 0000000..e69de29 diff --git a/packages/server/server/controllers/index.js b/packages/server/server/controllers/index.js new file mode 100644 index 0000000..e69de29 diff --git a/packages/server/server/routes/api.js b/packages/server/server/routes/api.js new file mode 100644 index 0000000..e69de29 diff --git a/packages/server/server/routes/auth.js b/packages/server/server/routes/auth.js new file mode 100644 index 0000000..e69de29 diff --git a/packages/server/server/server.js b/packages/server/server/server.js index 81fc4da..0230293 100644 --- a/packages/server/server/server.js +++ b/packages/server/server/server.js @@ -2,8 +2,6 @@ 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'); @@ -18,14 +16,10 @@ 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)); diff --git a/packages/server/server/socket.js b/packages/server/server/socket.js index 0ad49fc..e3aeefb 100644 --- a/packages/server/server/socket.js +++ b/packages/server/server/socket.js @@ -1,10 +1,14 @@ +// TODO const someSocketLogic = require('./middleware/socketssockets/...'); + module.exports = { - socket: io => { + enableSocket: io => { io.on('connection', () => console.log('connected')) io.on('connect', ()=> { - console.log('connected'); - io.emit('connected', {message: 'socket connected'}); + io.emit('connected', {message: 'socket connected'}); }) + + // TODO io = someSocketLogic(io); + return io; } } \ No newline at end of file