Skip to content

Commit e7128d7

Browse files
authored
Merge pull request #1 from NickRI/master
Some fixes
2 parents 1314cf9 + 76a0512 commit e7128d7

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/build
1111
yarn.lock
1212
/yarn.lock/
13+
log.txt
14+
public
1315

1416
# misc
1517
.DS_Store
@@ -23,4 +25,4 @@ yarn-debug.log*
2325
yarn-error.log*
2426

2527
# mockups
26-
/psd/
28+
/psd/

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ This is my PET Chat project that I'd like to share with you.
88

99
2) Install dependencies via npm `npm i` or yarn `yarn install`.
1010

11-
3) Start your web server `yarn start` || `npm run start`.
11+
3) Build ui application `npm run dev || prod`.
1212

13-
4) Open 2 Browser tabs and enter 2 different nicknames.
13+
4) Start web server `npm run server`.
1414

15-
5) Type anything in a chat.
15+
4.1) For fast start use `npm run start`
16+
17+
5) Open 2 Browser tabs and enter 2 different nicknames. Navigate to [http://localhost:5001](http://localhost:5001)
18+
19+
6) Type anything in a chat.
1620

1721
# Location of stuff
1822

@@ -33,4 +37,4 @@ This is my PET Chat project that I'd like to share with you.
3337

3438
# Build production
3539

36-
If you want to build a production version of my app you need to type `npm run prod` || `yarn prod` in a console. This will create public folder where everything will be compressed and minified.
40+
If you want to build a production version of my app you need to type `npm run prod` || `yarn prod` in a console. This will create public folder where everything will be compressed and minified.

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const express = require('express');
22
const app = express();
3-
const server = require('http').createServer(app);
4-
const io = require('socket.io')(server);
3+
const io = require('socket.io');
54
const port = process.env.PORT || 5001;
65
const fs = require('fs');
76

@@ -11,21 +10,19 @@ app.get('/', (req, res) => {
1110
res.sendFile(`${__dirname }./public/index.html`);
1211
});
1312

14-
io.on('connection', socket => {
13+
var sock = io.listen(app.listen(port));
14+
15+
sock.on('connection', socket => {
1516
console.log('a user connected');
1617

1718
socket.on('chat message', msg => {
1819
fs.appendFile('log.txt', `${msg.author}: ${msg.text} ${new Date()}\n`, (err) => {
1920
if (err) throw err;
2021
});
21-
io.emit('chat message', msg);
22+
sock.emit('chat message', msg);
2223
});
2324

2425
socket.on('disconnect', () => {
2526
console.log('a user disconnected');
2627
});
2728
});
28-
29-
server.listen(port, () => {
30-
console.log(`Server listening at port1 ${port}`);
31-
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"watch": "webpack --watch",
99
"client": "webpack-dev-server",
1010
"server": "nodemon index.js",
11-
"prod": "cross-env NODE_ENV=production webpack -p ",
11+
"dev": "cross-env NODE_ENV=development webpack",
12+
"prod": "cross-env NODE_ENV=production webpack -p",
1213
"start": "concurrently \"npm run client\" \"npm run server\" "
1314
},
1415
"dependencies": {

src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import MainApp from './app';
77

88
import io from 'socket.io-client';
99
import { sendMessage } from './actions/actionCreators';
10-
const socket = io('http://localhost:5001');
10+
const socket = io();
1111

1212
socket.on('chat message', (message) => {
1313
store.dispatch(sendMessage(message.author, message.text));

0 commit comments

Comments
 (0)