Skip to content

Commit

Permalink
use remote webui ip
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciareinoso committed Jul 26, 2024
1 parent 5f2f75d commit d2bcebd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 32 deletions.
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
env: {
WEBUI_ENDPOINT: process.env.WEBUI_ENDPOINT,
},
};

module.exports = nextConfig;
22 changes: 12 additions & 10 deletions utils/callDeviceGroupApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ function isValidDeviceGroupName(name: string): boolean {
return /^[a-zA-Z0-9-_]+$/.test(name);
}

const WEBUI_ENDPOINT = process.env.WEBUI_ENDPOINT || 'http://localhost:3000';

export const apiGetAllDeviceGroups = async () => {
try {
const response = await fetch(`/config/v1/device-group/`, {
const response = await fetch(`${WEBUI_ENDPOINT}/config/v1/device-group/`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -18,11 +20,11 @@ export const apiGetAllDeviceGroups = async () => {
};

export const apiGetDeviceGroup = async (name: string) => {
if (isValidDeviceGroupName(name)){
throw new Error(`Error getting device group: Invalid name provided.`);
if (!isValidDeviceGroupName(name)){
throw new Error(`Error getting device group: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/device-group/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/device-group/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -36,11 +38,11 @@ export const apiGetDeviceGroup = async (name: string) => {
};

export const apiPostDeviceGroup = async (name: string, deviceGroupData: any) => {
if (isValidDeviceGroupName(name)){
throw new Error(`Error updating device group: Invalid name provided.`);
if (!isValidDeviceGroupName(name)){
throw new Error(`Error updating device group: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/device-group/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/device-group/${name}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -55,11 +57,11 @@ export const apiPostDeviceGroup = async (name: string, deviceGroupData: any) =>
};

export const apiDeleteDeviceGroup = async (name: string) => {
if (isValidDeviceGroupName(name)){
throw new Error(`Error deleting device group: Invalid name provided.`);
if (!isValidDeviceGroupName(name)){
throw new Error(`Error deleting device group: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/device-group/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/device-group/${name}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Expand Down
23 changes: 13 additions & 10 deletions utils/callNetworkSliceApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ function isValidNetworkSliceName(name: string): boolean {
return /^[a-zA-Z0-9-_]+$/.test(name);
}

const WEBUI_ENDPOINT = process.env.WEBUI_ENDPOINT || 'http://localhost:3000';

export const apiGetAllNetworkSlices = async () => {
const url = `http://${WEBUI_ENDPOINT}/config/v1/network-slice`
try {
const networkSlicesResponse = await fetch(`/config/v1/network-slice`, {
const networkSlicesResponse = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -18,11 +21,11 @@ export const apiGetAllNetworkSlices = async () => {
};

export const apiGetNetworkSlice = async (name: string) => {
if (isValidNetworkSliceName(name)){
throw new Error(`Error getting network slice: Invalid name provided.`);
if (!isValidNetworkSliceName(name)){
throw new Error(`Error getting network slice: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/network-slice/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/network-slice/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -36,11 +39,11 @@ export const apiGetNetworkSlice = async (name: string) => {
};

export const apiPostNetworkSlice = async (name: string, sliceData: any) => {
if (isValidNetworkSliceName(name)){
throw new Error(`Error updating network slice: Invalid name provided.`);
if (!isValidNetworkSliceName(name)){
throw new Error(`Error updating network slice: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/network-slice/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/network-slice/${name}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -55,11 +58,11 @@ export const apiPostNetworkSlice = async (name: string, sliceData: any) => {
};

export const apiDeleteNetworkSlice = async (name: string) => {
if (isValidNetworkSliceName(name)){
throw new Error(`Error deleting network slice: Invalid name provided.`);
if (!isValidNetworkSliceName(name)){
throw new Error(`Error deleting network slice: Invalid name provided ${name}`);
}
try {
const response = await fetch(`/config/v1/network-slice/${name}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/network-slice/${name}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Expand Down
22 changes: 12 additions & 10 deletions utils/callSubscriberApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ function isValidSubscriberName(name: string): boolean {
return /^[a-zA-Z0-9-_]+$/.test(name);
}

const WEBUI_ENDPOINT = process.env.WEBUI_ENDPOINT || 'http://localhost:3000';

export const apiGetAllSubscribers = async () => {
try {
var response = await fetch(`/api/subscriber`, {
var response = await fetch(`http://${WEBUI_ENDPOINT}/api/subscriber`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -18,11 +20,11 @@ export const apiGetAllSubscribers = async () => {
};

export const apiGetSubscriber = async (imsi: string) => {
if (isValidSubscriberName(imsi)){
throw new Error(`Error getting subscriber: Invalid name provided.`);
if (!isValidSubscriberName(imsi)){
throw new Error(`Error getting subscriber: Invalid name provided. ${imsi}`);
}
try {
const response = await fetch(`/api/subscriber/imsi-${imsi}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/api/subscriber/imsi-${imsi}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand All @@ -36,11 +38,11 @@ export const apiGetSubscriber = async (imsi: string) => {
};

export const apiPostSubscriber = async (imsi: string, subscriberData: any) => {
if (isValidSubscriberName(imsi)){
throw new Error(`Error updating subscriber: Invalid name provided.`);
if (!isValidSubscriberName(imsi)){
throw new Error(`Error updating subscriber: Invalid name provided ${imsi}`);
}
try {
const response = await fetch(`/api/subscriber/imsi-${imsi}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/api/subscriber/imsi-${imsi}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -55,11 +57,11 @@ export const apiPostSubscriber = async (imsi: string, subscriberData: any) => {
};

export const apiDeleteSubscriber = async (imsi: string) => {
if (isValidSubscriberName(imsi)){
throw new Error(`Error deleting subscriber: Invalid name provided.`);
if (!isValidSubscriberName(imsi)){
throw new Error(`Error deleting subscriber: Invalid name provided ${imsi}`);
}
try {
const response = await fetch(`/api/subscriber/imsi-${imsi}`, {
const response = await fetch(`http://${WEBUI_ENDPOINT}/api/subscriber/imsi-${imsi}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Expand Down
1 change: 1 addition & 0 deletions utils/createNetworkSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const createNetworkSlice = async ({
};

try {
console.error(`Getting NS ${name}`);
const getNetworkSliceResponse = await apiGetNetworkSlice(name)
if (getNetworkSliceResponse.ok) {
throw new Error("Network slice already exists");
Expand Down
4 changes: 3 additions & 1 deletion utils/getGnbList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export interface GnbItem {
tac: number;
}

const WEBUI_ENDPOINT = process.env.WEBUI_ENDPOINT || 'http://localhost:3000';

export const getGnbList = async (): Promise<GnbItem[]> => {
try {
const response = await fetch("/config/v1/inventory/gnb", {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/inventory/gnb`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 3 additions & 1 deletion utils/getUpfList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export interface UpfItem {
port: string;
}

const WEBUI_ENDPOINT = process.env.WEBUI_ENDPOINT || 'http://localhost:3000';

export const getUpfList = async (): Promise<UpfItem[]> => {
try {
const response = await fetch("/config/v1/inventory/upf", {
const response = await fetch(`http://${WEBUI_ENDPOINT}/config/v1/inventory/upf`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit d2bcebd

Please sign in to comment.