You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
813 B
40 lines
813 B
const express = require("express");
|
|
const app = express();
|
|
const PORT = 4000;
|
|
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
app.use(express.json());
|
|
|
|
const http = require("http").Server(app);
|
|
const cors = require("cors");
|
|
|
|
const socketIO = require('socket.io')(http, {
|
|
cors: {
|
|
origin: "<http://localhost:3000>"
|
|
}
|
|
});
|
|
|
|
//👇🏻 Add this before the app.get() block
|
|
socketIO.on('connection', (socket) => {
|
|
console.log(`⚡: ${socket.id} user just connected!`);
|
|
|
|
socket.on("singIn", (test) => {
|
|
console.log(test);
|
|
});
|
|
|
|
socket.on('disconnect', () => {
|
|
socket.disconnect()
|
|
console.log('🔥: A user disconnected');
|
|
});
|
|
});
|
|
|
|
app.get("/api", (req, res) => {
|
|
res.json({
|
|
message: "Hello world",
|
|
});
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server listening on ${PORT}`);
|
|
}); |