@whiteleaf

Как указать нужный адрес для api?

Подскажите, пожалуйста, как мне работая на порте 4200 иметь возможность получать информация по api.
Чтобы сразу видеть изменения в реальном времени.

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());
  }

}
  • Вопрос задан
  • 206 просмотров
Пригласить эксперта
Ответы на вопрос 1
Балансировать по нодам например nginx'ом
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы