33 lines
754 B
JavaScript
33 lines
754 B
JavaScript
|
import express from 'express';
|
||
|
|
||
|
import { Server } from 'socket.io'
|
||
|
import { createServer } from 'http';
|
||
|
import { socketHandler } from './gridwar.js';
|
||
|
|
||
|
const app = express()
|
||
|
const server = createServer(app);
|
||
|
const io = new Server(server);
|
||
|
const port = process.argv[2] || 3069;
|
||
|
|
||
|
app.use((req, res, next) => {
|
||
|
let param = new URL(`https://gw.dervland.net/${req.originalUrl}`).searchParams.get('token');
|
||
|
if (param) {
|
||
|
res.cookie('token', param, {
|
||
|
maxAge: 1000 * 60 * 60 * 24 * 7,
|
||
|
path: '/'
|
||
|
});
|
||
|
}
|
||
|
next();
|
||
|
});
|
||
|
app.use(express.static('./static'));
|
||
|
|
||
|
io.on('connection', (socket) => {
|
||
|
socketHandler(socket, io)
|
||
|
})
|
||
|
|
||
|
server.listen(port, () => {
|
||
|
console.log(`Web server listening on port ${port}`)
|
||
|
})
|
||
|
|
||
|
|