我正在使用一个新的angular-cli"my-project"并创建了一个简单的虚拟服务.我希望此服务连接到本地计算机上的laravel后端.我发现后端的Angular-CLI代理不起作用,但即使这些步骤对我来说也不起作用.Chrome仍然会访问localhost:4200.
我的服务
import { Injectable } from '@angular/core';
import {Http, Response} from '@angular/http';
@Injectable()
export class DummyService {
constructor(private http: Http) {
console.log('Hello dummyService');
}
getMessages() {
return this.http.get('/backend/public/api/auth/login').map((res: Response) => res.json());
}
}
Run Code Online (Sandbox Code Playgroud)
我的proxy.config.json
{
"/backend": {
"target": "http://localhost:81/laravelapi",
"secure": false,
"pathRewrite": {"^/backend" : ""},
"changeOrigin": true,
"logLevel": "debug"
}
}
Run Code Online (Sandbox Code Playgroud)
我的开始是package.json的开头
"start": "ng serve --proxy-config proxy.config.json",
Run Code Online (Sandbox Code Playgroud)
启动时,我得到以下日志消息:
** NG Live Development Server is running on http://localhost:4200 **
0% compiling
10% building modules 1/1 modules 0 active …Run Code Online (Sandbox Code Playgroud)