- add: frontend webpage for login/register
This commit is contained in:
23
frontend/src/utils/consul.js
Normal file
23
frontend/src/utils/consul.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from "axios";
|
||||
|
||||
const CONSUL_URL = process.env.REACT_APP_CONSUL_URL;
|
||||
|
||||
/**
|
||||
* Fetch the IP and port of the service from Consul.
|
||||
* @param {string} serviceName - The name of the registered service.
|
||||
* @returns {Promise<{Address: string, ServicePort: number}>}
|
||||
*/
|
||||
export async function getServiceAddress(serviceName) {
|
||||
try {
|
||||
const response = await axios.get(`${CONSUL_URL}/v1/catalog/service/${serviceName}`);
|
||||
if (response.data && response.data.length > 0) {
|
||||
const { ServiceAddress, ServicePort } = response.data[0]; // Get the first instance
|
||||
return { ServiceAddress, ServicePort };
|
||||
} else {
|
||||
throw new Error("Service not found in Consul");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch service address from Consul:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user