You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import {get_client, init_db, insert_one} from './src/utils/database.js';
import UserRoute from "./src/routes/user.route.js";
import SpotifyRoute from "./src/routes/spotify.route.js";
import DownloaderRoute from "./src/routes/downloader.route.js";
import dotenv from "dotenv";
import { Server } from "socket.io";
import { createServer } from 'http';
import {check} from "./src/utils/file_checker.js";
dotenv.config();
console.clear();
const app = express();
const PORT = process.env.PORT || 3000;
// Create HTTP server
const server = createServer(app);
// Attach Socket.IO to the HTTP server
const io = new Server(server, {
cors: {
origin: "*"
}
});
io.on('connection', (socket) => {
console.log('A user connected:', socket.id);
check(socket);
socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);
});
});
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('test'));
app.use('/api/users', UserRoute)
app.use('/api/spotify', SpotifyRoute);
app.use('/api/downloader', DownloaderRoute);
await get_client();
await init_db('mydatabase');
// Listen on the HTTP server (not the Express app)
server.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
console.log(`Socket.IO is ready for connections`);
})