2

I am running an Angular 2 application using lite-server. When I attempt to make a get request I get a 404 error for external links. I can make a successful get to a file inside the directory.

Response {_body: Object, status: 404, ok: false, statusText: "Not Found",     headers: Headers…}
 _body:Object
 headers:Headers 
 ok:false
 status:404
 statusText:"Not Found"
 type:2
url:null

proto:Body

Here is my conponent with the get request code:

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { BreadcrumbService } from './breadcrumbService';
import 'rxjs/add/operator/map';

import { Http, Response, RequestOptions, Headers } from '@angular/http';
@Component({
  moduleId: module.id,
  providers: [ BreadcrumbService],
  templateUrl: 'html/appList.html',
  styleUrls: ['css/list.css']

})
export class HealthComponent {
  constructor(private http: Http) {
    this.http = http;
    this.http.get('https://jsonplaceholder.typicode.com/')
    .map(response => response.json())
    .subscribe(
      function(response) { console.log(response)},
      function(error) { console.log("Error happened " + error)},
      function() { console.log("the subscription is completed")}
  );
 }

}

I have tried to configure my bs-config.js file as seen in the here:

https://github.com/johnpapa/lite-server/issues/100

but im not sure if that is even the cause of my problems. Here is that file:

var proxy = require('http-proxy-middleware');
var apiProxy = proxy('/api',              {target:'http://jsonplaceholder.typicode.com/posts/1', changeOrigin: true});
module.exports = {
  "port": 8000,
  // "files": ["./src/**/*.{html,htm,css,js}"],
  "server": {
    middleware: {
      1:apiProxy
    },
    "baseDir": [
      // "./src",
       "./"
    ]
   }
 };

Any help would be appreciated!

Adam Harrison
  • 363
  • 5
  • 16
Malinda Miller
  • 181
  • 2
  • 11

0 Answers0