minor changes
This commit is contained in:
@@ -16,12 +16,10 @@
|
||||
#messages > li:nth-child(odd) { background: #efefef; }
|
||||
</style>
|
||||
|
||||
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>)
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
const socket = io();
|
||||
|
||||
const form = document.getElementById('form');
|
||||
const input = document.getElementById('input');
|
||||
const socket = io();
|
||||
|
||||
form.addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
@@ -30,6 +28,7 @@
|
||||
input.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
21
index.js
21
index.js
@@ -6,16 +6,15 @@ const app = express()
|
||||
const path = require('path');
|
||||
const { insertUser, isUserExists, client } = require('./backend/db.js');
|
||||
const { chat } = require('./backend/socket.js');
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
const saltRounds = 10;
|
||||
|
||||
const { Server } = require("socket.io");
|
||||
const { Server } = require('socket.io');
|
||||
const { createServer } = require('node:http');
|
||||
const server = createServer(app);
|
||||
const { join } = require('node:path');
|
||||
const io = new Server(server);
|
||||
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
//TODO change password option will be cool
|
||||
@@ -25,7 +24,7 @@ app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use('/static', express.static('frontend'))
|
||||
app.use('/socket', express.static('node_modules/socket.io/client-dist'));
|
||||
app.use('/socket.io', express.static('node_modules/socket.io/client-dist'));
|
||||
app.use(session({
|
||||
secret: process.env.SESSION_SECRET,
|
||||
resave: true,
|
||||
@@ -61,20 +60,6 @@ app.get('/', (req, res) => {
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('a user connected');
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('user disconnected');
|
||||
});
|
||||
|
||||
socket.on('connection', (socket) => {
|
||||
console.log('message: ', + msg);
|
||||
})
|
||||
});
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
socket.on('chat message', (msg) => {
|
||||
console.log('message: ' + msg);
|
||||
});
|
||||
});
|
||||
|
||||
// run server
|
||||
|
||||
Reference in New Issue
Block a user