forked from platzi/reactjs-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 747 Bytes
/
index.js
File metadata and controls
36 lines (28 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Module dependencies
*/
import express from 'express';
import http from 'http';
import engine from 'socket.io';
import dbapi from './db-api';
const port = 3000;
const app = express();
// Configurar la ruta de archivos estáticos
app.use('/', express.static(__dirname + '/public'));
app.get('/pokemons', (req, res) => {
dbapi.pokemons.find((pokemons) => {
res.json(pokemons);
})
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
})
let server = http.createServer(app).listen(port, () => {
console.log(`El servidor está escuchando en el puerto ${port}`);
});
const io = engine.listen(server);
io.on('connection', (socket) => {
socket.on('message', (msg) => {
io.emit('message', msg);
})
})