How to generate my Postgresql Baseurl (link) that is in Heroku to integrate to my Angular front end?

Asked

Viewed 69 times

1

My question is: how do I link (baseurl) to which my front-end access the data coming from this database (Postgresql) that is hosted on Heroku?

My Heroku’s Postgresql releases this information:

inserir a descrição da imagem aqui

As the above img I have host, database and so on, now I need to put some of this information in this part of my code front-end (Service - Service) eventosUrl = '???'; to release the data from the Heroku comic:

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

@Injectable()
export class EventoService {

//eventosUrl = 'http://localhost:8080/eventos';
eventosUrl = '???';

constructor(private http: HttpClient) { }

listar() {
  return this.http.get<any[]>(this.eventosUrl);
  }
}

I don’t know if I need to put something in my file application properties since I locally put this to free access to database via Ajax (requests):

FILE application.properties:

origem-permitida=http://localhost:4200
  • Your frontend should not access the database. If your front knows how to access the database, any user can take this information through the browser and hack your database.

  • Look is what I’ve learned, but I can do this integration through the localhost, as per the code above. I don’t know how you have this information that you refer to, but a link, i.e., the baseURL. This layer is of service and is not directly in the viwer HTML who treats this is the framework Angular.

1 answer

1


creates a configuration file with the following content:

export const API_CONFIG = {
     baseUrl: "https://nome-do-app.herokuapp.com",
}

In each service you import this file and the methods that communicate with the api you put this way:

return this.http.get<Objeto[]>(`${API_CONFIG.baseUrl}/nome-da-rota`);

That way, if you ever change https://nome-do-app.herokuapp.com for https://nome-do-app2.herokuapp.com, you change only in the configuration file and no need to touch nhm service.

Browser other questions tagged

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