Угловой - zone.js: 3243 ОПЦИИ http://localhost:8888/clientportal-app/backend/api/clientquotelanding net :: ERR_CONNECTION_REFUSED - PullRequest
0 голосов
/ 19 сентября 2019

Я разрабатываю веб-портал, используя Laravel-5.8 в качестве бэкэнда и Angular-7 в качестве внешнего интерфейса.Я получаю сообщение об ошибке в консоли и не знаю, как ее устранить:

zone.js: 3243 ОПЦИИ http://localhost:8888/clientportal-app/backend/api/clientquotelanding net :: ERR_CONNECTION_REFUSED

ApiController.php

public function createClientQuote(Request $request) {
    $request->validate([
      'first_name' => 'required',
      'last_name' => 'required',
      'email' => 'required|email',
      'phone' => 'required|max:14',
      'business_name' => 'required',
      'truck_type' => 'required',
      'truck_required' => 'required',
      'quote_origin' => 'required',
      'quote_destination' => 'required',
      'commodity' => 'required',  
      'loading_date' => 'required' 
  ]);
  $clientquote = new ClientQuote([
      'first_name' => $request->first_name,
      'last_name'=> $request->last_name,
      'email' => $request->email,
      'phone' => $request->phone,
      'business_name' => $request->business_name,
      'address' => $request->address,
      'comment' => $request->comment,
      'truck_type' => $request->truck_type,
      'truck_required' => $request->truck_required,
      'quote_origin' => $request->quote_origin,
      'quote_destination' => $request->quote_destination,
      'commodity' => $request->commodity,  
      'loading_date' => $request->loading_date
    ]);
    $clientquote->save();

     $mainData = array();
     $mainData['to'] = $clientquote->toArray()['email'];
     $mainData['from'] = "support@tsllimited.com";
     $mainData['subject'] = "Client Quote";
     $mainData['content'] = "Your Quote have been successfully received. You will hear from us shortly through the provided email. Thank you!";

     $this->mailSend($mainData);

    return response()->json([
        'message' => 'Quote Successfully Sent!'
    ], 201);
}

api.php

Route::group([
  ], function () {
  Route::post('clientquotelanding','ApiController@createClientQuote');
});

client-quote-landing.ponent

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiService } from '../../shared/services/api.service';
import { Router } from '@angular/router';
import { SnotifyService } from 'ng-snotify';

@Component({
  selector: 'app-client-quotes-landing',
  templateUrl: './client-quotes-landing.component.html',
  styleUrls: ['./client-quotes-landing.component.scss']
})
export class ClientQuotesLandingComponent implements OnInit {

formattedAddress = '';
truck_types = [];

public form = {
  first_name : null,
  last_name : null,
  email : null,
  phone : null,
  address : null,
  business_name : null,
  truck_required : null,
  truck_type : null,
  quote_origin : null,
  quote_destination : null,
  commodity : null,
  loading_date : null,
  comment : null,
};

public error = {
 'first_name' : null,
 'last_name' : null,
 'email' : null,
 'phone' : null,
 'address' : null,
 'business_name' : null,
 'truck_required' : null,
 'truck_type' : null,
 'quote_origin' : null,
 'quote_destination' : null,
 'commodity' : null,
 'loading_date' : null,
 'comment' : null
};

constructor(
  private api: ApiService,
  private token: TokenService,
  private router: Router,
  private notify: SnotifyService
) {
}

 ngOnInit() {
   window.dispatchEvent(new Event('load'));
   window.dispatchEvent(new Event('resize'));
 }

onSubmit(){
  var header = {
 'Content-Type': 'application/json'
}
return this.api.post('clientquotelanding', this.form, header).subscribe(
 },
 );
 }
}

api.service.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class ApiService {

constructor(private http: HttpClient) { }

host = 'http://localhost:8888/clientportal-app/backend';
baseURL = this.host + '/api/';

post(url, data, headers){
  return this.http.post(`${this.baseURL}${url}`, data, { headers: new HttpHeaders(headers) } )
}

get(url, headers){
  return this.http.get(`${this.baseURL}${url}`, { headers: new HttpHeaders(headers) } )
}

delete(url,headers){
  return this.http.delete(`${this.baseURL}${url}`, { headers: new HttpHeaders(headers) } )
}

put(url, data, headers){
  return this.http.put(`${this.baseURL}${url}`, data, { headers: new HttpHeaders(headers) } )
}
}

При предварительном просмотре сети я получил:

network error

Как мне решить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...