From 7531d56c6ae97d3a89fe5e6e68473f7edcfd2081 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Wed, 20 Oct 2021 14:38:12 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Added=20a=20hostname=20generator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/fileops.actions.tsx | 5 ++- src/client/constants/endpoints.ts | 46 ++++++++++++++++---- src/client/context/socket/socket.context.tsx | 4 +- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index 05687c0..11feb0e 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -2,6 +2,7 @@ import axios from "axios"; import { IFolderData, IExtractedComicBookCoverFile } from "threetwo-ui-typings"; import { API_BASE_URI, + COMICBOOKINFO_SERVICE_URI, IMPORT_SERVICE_BASE_URI, SOCKET_BASE_URI, } from "../constants/endpoints"; @@ -74,7 +75,7 @@ export const fetchComicBookMetadata = ); await axios .request({ - url: "http://localhost:8050/api/getComicCovers", + url: `${API_BASE_URI}/getComicCovers`, method: "POST", data: { extractionOptions, @@ -190,7 +191,7 @@ export const fetchComicVineMatches = (searchPayload) => (dispatch) => { axios .request({ - url: "http://localhost:3080/api/comicvine/fetchresource", + url: `${COMICBOOKINFO_SERVICE_URI}/fetchresource`, method: "POST", data: { format: "json", diff --git a/src/client/constants/endpoints.ts b/src/client/constants/endpoints.ts index 2f009b4..541b86b 100644 --- a/src/client/constants/endpoints.ts +++ b/src/client/constants/endpoints.ts @@ -1,8 +1,38 @@ -export const COMICBOOKINFO_SERVICE_URI = - `http://${process.env.DOCKER_HOST}/api/comicvine` || - "http://localhost:3080/api/comicvine"; -export const API_BASE_URI = "http://localhost:8050/api/"; -export const IMPORT_SERVICE_BASE_URI = - `http://${process.env.DOCKER_HOST}/api/import` || - "http://localhost:3000/api/import"; -export const SOCKET_BASE_URI = "ws://localhost:8051"; +export const hostURIBuilder = (options: Record): string => { + return ( + options.protocol + + "://" + + options.host + + ":" + + options.port + + options.apiPath + ); +}; + +export const COMICBOOKINFO_SERVICE_URI = hostURIBuilder({ + protocol: "http", + host: process.env.DOCKER_HOST || "localhost", + port: "3080", + apiPath: "/api/comicvine", +}); + +export const API_BASE_URI = hostURIBuilder({ + protocol: "http", + host: process.env.DOCKER_HOST || "localhost", + port: "8050", + apiPath: "/api", +}); + +export const IMPORT_SERVICE_BASE_URI = hostURIBuilder({ + protocol: "http", + host: process.env.DOCKER_HOST || "localhost", + port: "3000", + apiPath: "/api/import", +}); + +export const SOCKET_BASE_URI = hostURIBuilder({ + protocol: "ws", + host: process.env.DOCKER_HOST || "localhost", + port: "8051", + apiPath: ``, +}); diff --git a/src/client/context/socket/socket.context.tsx b/src/client/context/socket/socket.context.tsx index acf8cee..e948030 100644 --- a/src/client/context/socket/socket.context.tsx +++ b/src/client/context/socket/socket.context.tsx @@ -8,9 +8,7 @@ import { success } from "react-notification-system-redux"; const WebSocketContext = createContext(null); export const WebSocketProvider = ({ children }): ReactElement => { const dispatch = useDispatch(); - const socketHost = - `http://${process.env.DOCKER_HOST}:8051` || SOCKET_BASE_URI; - const socket: Socket = io(socketHost); + const socket: Socket = io(SOCKET_BASE_URI); socket.on("connect", () => { dispatch({