import _ from 'lodash';
import Express from 'express';
import { createServer } from "http";
import { Server } from "socket.io";
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PORT = process.env.PORT || 8080;
// Express
const app = new Express();
const httpServer = createServer(app);
const io = new Server(httpServer);
app.use(Express.static(`${__dirname}/static/js/`));
app.use(Express.static(`${__dirname}/static/css`));
app.use(Express.static(`${__dirname}/static/img/chesspieces/wikipedia`));
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
const playerId = _.uniqueId();
console.log(playerId + ' connected');
socket.on('disconnect', () => {
console.log(playerId + ' disconnected');
});
});
httpServer.listen(PORT, () => {
console.log(`Server is running on port: ${PORT}`);
});