Skip to content

Commit e6b92c3

Browse files
committed
El frontend accede a la API
1 parent 585b3d6 commit e6b92c3

File tree

4 files changed

+91
-19
lines changed

4 files changed

+91
-19
lines changed

01-contenedores/lemoncode-challenge/backend/steps.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

01-contenedores/lemoncode-challenge/frontend/package-lock.json

Lines changed: 82 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

01-contenedores/lemoncode-challenge/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"dependencies": {
1313
"ejs": "^3.1.6",
1414
"express": "^4.17.1",
15-
"mongodb": "^4.1.1"
15+
"node-fetch": "^3.0.0"
1616
}
1717
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
//Módulos
2+
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
23
const express = require('express'),
3-
app = express(),
4-
mongodb = require('mongodb');
4+
app = express();
5+
6+
const LOCAL = 'http://localhost:5000/api/topics';
57

68
app.set('view engine', 'ejs');
79

810
app.get('/', async (req, res) => {
911

10-
//Recuperar topics de mongodb
11-
const client = await new mongodb.MongoClient('mongodb://localhost:27017').connect();
12-
13-
const db = client.db('TopicstoreDb');
14-
15-
const topics = await db.collection('Topics').find().toArray();
16-
17-
console.log(`Topics: ${topics.length}`);
18-
console.log(topics);
12+
//Recuperar topics de la API
13+
const response = await fetch(process.env.API_URI || LOCAL);
14+
const topics = await response.json();
1915

2016
res.render('index', { topics });
2117

2218
});
2319

2420
app.listen(3000, () => {
25-
console.log('Server running on port 3000');
21+
console.log(`Server running on port 3000 with ${process.env.API_URI || LOCAL}`);
2622
});

0 commit comments

Comments
 (0)