import "dotenv/config";
import express from "express";
import { createServer } from "http";
import router from "routes/router";
import cors from "cors";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-adapter";
import { pubClient, subClient } from "modules/redis";
import "modules/chron";

const app = express();
const server = createServer(app);

export const io = new Server(server, {
	adapter: createAdapter(pubClient, subClient),
	cors: {},
});

app.use(cors());
app.use(express.json());
app.use(router);

server.listen(process.env.DISCORD_SERVER_PORT, () => {
	console.log(`Server running on port ${process.env.DISCORD_SERVER_PORT}`);
});
