35 lines
838 B
JavaScript
35 lines
838 B
JavaScript
const express = require("express");
|
|
const { Server } = require("socket.io");
|
|
const http = require("http");
|
|
const app = express();
|
|
const path = require("path");
|
|
|
|
app.use(express.static(path.join(__dirname, './dist')));
|
|
app.disable("x-powered-by");
|
|
|
|
app.get('*', (req, res) => res.sendFile(path.join(__dirname, './dist', 'index.html')));
|
|
|
|
const server = http.createServer(app);
|
|
|
|
const io = new Server(server, {
|
|
cors: {origin: "*"},
|
|
pingTimeout: 30000,
|
|
pingInterval: 10000
|
|
});
|
|
|
|
server.on('error', (error) => {
|
|
console.error('Server error:', error);
|
|
});
|
|
|
|
const PORT = process.env.PORT || 5237;
|
|
server.listen(PORT, () => {
|
|
console.log(`Server running on port ${PORT}`);
|
|
});
|
|
|
|
process.on('SIGINT', () => {
|
|
console.log('Server shutting down...');
|
|
server.close(() => {
|
|
console.log('Server closed');
|
|
process.exit(0);
|
|
});
|
|
}); |