W
W
whiteleaf2017-10-04 18:20:26
css
whiteleaf, 2017-10-04 18:20:26

How to specify the correct address for api?

Tell me, please, how do I work on port 4200 to be able to receive information via api.
To immediately see the changes in real time.
api.js

const express = require('express');
const router = express.Router();

const model = require('../models/user');
//const axios = require('axios');


/* GET api listing. */
router.get('/', (req, res) => {
  res.send('api works');
});

// Get all posts
router.get('/users', (req, res) => {

  model.find({})
    .exec(function(err,users){
      if (err) throw err;
      res.json(users);
  });


  // Get posts from the mock api
  //// This should ideally be replaced with a service that connects to MongoDB
  //axios.get(`${API}/users`)
  //  .then(posts => {
  //    res.status(200).json(posts.data);
  //  })
  //  .catch(error => {
  //    res.status(500).send(error)
  //  });


});

module.exports = router;

users.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class UsersService {

  constructor(private http: Http) { }

  // Get all posts from the API
  getAllUsers() {
    return this.http.get('/api/users')
      .map(res => res.json());
  }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Gerasimov, 2017-10-04
@Omashu

Balance across nodes like nginx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question