我将angular 2与laravel php框架一起用于我的api。我的Angular 2项目正在运行
http://localhost:4200/
当我的laravel php框架运行在
http://localhost:80/laravel/public
当我在Angular2项目中运行这个时:
getAllProfessionals():Observable<any> {
return this.http.get(globals.baseUrl+'/professionals/', {headers:this.utilService.getHeadersJson()}).map(this.utilService.map);
}
我的浏览器中出现此错误:
加载失败
http://localhost/laravel/public/api/v1/professionals/
以下内容:
飞行前的响应无效(重定向)
globals.baseurl是
http://localhost/laravel/public/api/v1/
这是this.utilservice的电话
getHeadersJson() {
let headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer ' + localStorage.getItem('token'));
return headers;
}
map(response: Response): any {
return response.json();
}
我在这里做错什么了?我的api调用有问题吗?
当我这样做时,接到电话:
getCountrys(filter):Observable<any> {
return this.http.get(globals.baseUrl+'/country/' + filter, {headers:this.utilService.getHeadersJson()}).map(this.utilService.map);
}
让国家运转起来!
当我转到URL时:
http://localhost/laravel/public/api/v1/professionals/
这就是回报:
请帮忙!
以下是位于“我的路由”文件夹中的laravel api.php文件中的路由:
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::group([ 'prefix' => 'v1'], function () {
Route::resource('register', 'v1\RegisterController');
Route::resource('paintype', 'v1\PainTypeController');
Route::resource('painlevel', 'v1\PainLevelController');
Route::resource('painkiller', 'v1\PainKillersController');
Route::resource('profession', 'v1\ProfessionsController');
Route::resource('qualification', 'v1\QualificationsController');
Route::resource('specialities', 'v1\SpecialitiesController');
Route::resource('problems', 'v1\ProblemsController');
Route::resource('user', 'v1\UserController');
Route::post('login', 'v1\AuthController@login');
Route::post('professionals', 'v1\ProfessionalsController@store');
Route::post('patients', 'v1\PatientsController@store');
Route::get('country/{text}', 'v1\LocationController@getCountries');
Route::get('region/{id}', 'v1\LocationController@getRegions');
Route::get('city/{id}', 'v1\LocationController@getCities');
Route::get('reviews/{username}', 'v1\ReviewController@show');
Route::group(['middleware' => ['before' => 'jwt.auth']], function () {
Route::resource('post-job', 'v1\PostJobController');
Route::post('reviews', 'v1\ReviewController@store');
Route::get('profile', 'v1\AuthController@profile');
Route::get('jobs/listjob', 'v1\PostJobController@getMyJobs');
});
});