我有一个 Angular 2.0 应用程序,最近我添加了带有以下 bs-config.js 的 http-proxy-middleware:
var proxyMiddleware = require('http-proxy-middleware');
module.exports = {
server: {
port: 3000,
middleware: {
1: proxyMiddleware('/WorkLocation', {
target: 'http://localhost/Perform/Company/WorkLocation',
changeOrigin: false,
logLevel: 'debug'
}),
2: require('connect-history-api-fallback')({index: '/index.html', verbose: true})
}
}
};
然后我有这样的服务:
export class WorkLocationsService extends BaseRestfulService<WorkLocationItemModel[]> {
private workLocationsServiceUrl: string = '/WorkLocation/EditList/111014/73442';
constructor(protected _http: Http) { super(_http) }
public getWorkLocations(): Observable<WorkLocationItemModel[]> {
return this.callApiEndPoint(null, this.workLocationsServiceUrl, HttpVerb.Get);
};
当我通过它启动我的应用程序时,会启动npm start
bs-config.js 代理设置,我会看到以下输出:
[1] [HPM] GET /WorkLocation/EditList/111014/73442 -> http://localhost/Perform/Company/WorkLocation
[1] 17.02.09 20:44:09 404 GET /WorkLocation/EditList/111014/73442
所以看起来 HPM 代理正在做正确的翻译,但在下面的行中,我在来自 WorkLocationService 调用的 GET 上收到 404 错误。如果我的服务看起来配置正确,为什么它不能通过代理?我错过了什么吗?