Chats were added
This commit is contained in:
25
app.js
25
app.js
@@ -8,12 +8,27 @@ import commentRoutes from './routes/comments.js';
|
||||
import communityRoutes from './routes/communities.js';
|
||||
import offerRoutes from './routes/offers.js';
|
||||
|
||||
// Chat stuff
|
||||
import { createServer } from 'http';
|
||||
import { Server } from 'socket.io';
|
||||
import { initializeSocketIO } from './socket/chatSocket.js';
|
||||
import chatRoutes from './routes/chat.js';
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
const httpServer = createServer(app);
|
||||
const io = new Server(httpServer, {
|
||||
cors: {
|
||||
origin: '*',
|
||||
methods: ['GET', 'POST']
|
||||
}
|
||||
});
|
||||
|
||||
app.use(express.json());
|
||||
app.use(cors());
|
||||
|
||||
|
||||
let corsOptions = {
|
||||
origin: '*', // Reemplaza con el origen permitido
|
||||
optionsSuccessStatus: 200 // Algunos navegadores (como IE11) requieren este estado
|
||||
@@ -34,6 +49,8 @@ ENDPOINT HTTP REQ ACCIÓN RES
|
||||
/api/user/all - GET (Ver todos los usuarios) Todos los usuarios
|
||||
/api/user/:userID - DELETE (Eliminar usuario) Administradores o Usuario.
|
||||
*/
|
||||
app.set('io', io);
|
||||
|
||||
|
||||
app.use('/', indexRoutes); // Rutas base
|
||||
app.use('/api', apiRoutes); // Rutas de API
|
||||
@@ -44,8 +61,12 @@ app.use('/uploads', express.static('uploads'));
|
||||
app.use('/api/offers', express.static('uploads'));
|
||||
app.use('/api/offers', offerRoutes); // Rutas de ofertas
|
||||
app.use('/api/communities', communityRoutes); // Rutas de comunidades
|
||||
app.use('/api/chat', chatRoutes); // Rutas de chat
|
||||
|
||||
app.listen(port, () => {
|
||||
initializeSocketIO(io);
|
||||
|
||||
// Iniciar el servidor HTTP
|
||||
httpServer.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`);
|
||||
console.log(`URL at: http://localhost:${port}`)
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user