Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get('/:id', (req, res) => {
- const id = req.params.id;
- const details = { '_id': new ObjectID(id) };
- db.collection('poems').find(details).toArray((err, result) => {
- if (err) return console.log(err)
- res.render('card.pug', {mongo: result})
- })
- })
- app.get('/', (req, res) => {
- db.collection('poems').find().toArray((err, result) => {
- if (err) return console.log(err)
- res.render('index.pug', {mongo: result})
- })
- })
- class Api {
- constructor () {
- this.baseURL = "http://localhost:3000";
- }
- _get (path) {
- return fetch (`${this.baseURL}${path}`, {
- method: "get"
- })
- }
- getPosts () {
- return this._get("/тут id стиха из mongo")
- .then (data => {
- return data.json()
- })
- .catch (err=>{
- console.error(err);
- return Promise.resolve([])
- })
- }
- }
- const createP = ()=> document.createElement("p")
- const api = new Api ();
- document.querySelector("#id карточки").addEventListener("click", ()=>{
- api.getPosts()
- .then (data=> {
- const p = createP ()
- p.textContent = el.title
- })
- });
Add Comment
Please, Sign In to add comment