35 lines
700 B
JavaScript
35 lines
700 B
JavaScript
import path from 'path';
|
|
import express from 'express';
|
|
import fs from 'fs';
|
|
import { createServer } from 'http';
|
|
import { Server } from 'socket.io';
|
|
// Create a server on port 3000
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
const app = express();
|
|
const server = createServer(app);
|
|
// socket.io
|
|
|
|
const io = new Server(server, {
|
|
cors: {
|
|
origin: '*',
|
|
},
|
|
});
|
|
|
|
server.listen(PORT, function () {
|
|
console.log('Server listening at port %d', PORT);
|
|
});
|
|
|
|
// Optionally routing your app
|
|
// app.use(express.static(path.join(__dirname, '../client')));
|
|
|
|
io.on('connection', function (socket) {
|
|
socket.on('save', function (data) {
|
|
//...
|
|
});
|
|
|
|
socket.on('load', function () {
|
|
///...
|
|
});
|
|
});
|