我正在使用lite-server运行Angular 2应用程序。当我尝试发出get请求时,外部链接出现404错误。我可以成功获取目录中的文件。
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
原:身体
以下是我的conponent获取请求代码:
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")}
);
}
}
我试图配置我的bs-config.js文件,如下所示:
https://github.com/johnpapa/lite-server/issues/100
但我不确定这是否是我的问题的原因。这是该文件:
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",
"./"
]
}
};
任何帮助将不胜感激!