Source URL in Angular REST request

Asked

Viewed 30 times

0

Hello

In the REST request of the Ionic application with Angular is automatically added the source URL:

http://localhost:8100/127.0.0.1:5000/medicao? start date=2020-12-13&end date=2020-12-20

when the right one would be:

http://127.0.0.1:5000/medica? start date=2020-12-13&end date=2020-12-20

I don’t have http interceptors in the code, I can’t identify where to remove this "http://localhost:8100" from the top

The request in Angular:

public  apiURL = '127.0.0.1:5000'

getMedicoes(){
    const headers = new HttpHeaders()
      .set('Content-Type', 'application/json');

    let param: any = {datainicial: '2020-12-13', datafinal: '2020-12-20'};
    console.log(this.http)
    return this.http.get<any>(this.apiURL+'/medicao',{headers: headers, params: param}).toPromise();
  }

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    Ng2GoogleChartsModule
  ],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],

I appreciate any kind of help, because if I had the trouble to write this question is because I’m already at least 4 hours trying to solve this problem, which for some should be very basic.

  • You could put the code snippet where vc assigns the URL address to the apiURL variable?

  • If I remove this variable the request will get http://localhost:8100/medicao? starting date=2020-12-13&end date=2020-12-20

1 answer

1

In your service, include the http protocol in the signature of the apiURL variable:

public apiURL = 'http://127.0.0.1:5000'
  • It worked. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.