muke1908 / chat-e2ee

End-to-end encrypted disposable chat sessions, exchange sensitive information with peer safely and securely.
https://chat-e2ee-2.azurewebsites.net/
Apache License 2.0
323 stars 198 forks source link

Allow to set server endpoint in chate2ee/service module #288

Closed muke1908 closed 1 year ago

muke1908 commented 1 year ago

Currently the module makes all request to / path. Allow user to set any base url. Take URL as an arg in createChatInstance function.

https://github.com/muke1908/chat-e2ee/blob/94f764f4937632e34e4a18ce6ab13e783c032e52/service/src/sdk.ts#L14

KalebArmbrust commented 1 year ago

@muke1908 Hey, I would love to give this a go, can you assign this to me?

muke1908 commented 1 year ago

@KalebArmbrust sure , go ahead

KalebArmbrust commented 1 year ago

@muke1908 Hey this is all pretty new to me. Can you possibly give me a hint or some direction? All I've done so far is add URL as an argument like you mentioned. Screenshot 2023-05-11 114637

muke1908 commented 1 year ago

Hi @KalebArmbrust , The simplest way I can suggest is instead of taking it in arg, let's define a separate function setConfig

const chate2eeConfig = {};
export const setConfig = (apiURL, socketURL) => {
     chate2eeConfig = { apiURL, socketURL }
}

export const configContext = () => chate2eeConfig;

import configContext in makeRequest file, and use it in BASE_URI, const { apiURL } = configContext();

export the setConfig from sdk.ts so that users can explicitly call setConfig to set URLs before creating an instance.

Feel free to ask if you have any questions.

KalebArmbrust commented 1 year ago

@muke1908 I have added the new function in sdk.ts and exported it, and imported configContext to the makeRequest.ts file but I am not sure how to use it in the BASE_URI

Screenshot 2023-05-12 100854

Screenshot 2023-05-12 100906

muke1908 commented 1 year ago

@KalebArmbrust it can be something like: const BASE_URI = apiURL || (process.env.NODE_ENV === "production" ? 'https://chat-e2ee-2.azurewebsites.net' : '');

Also, you need to move it inside makeRequest function.

KalebArmbrust commented 1 year ago

@muke1908 Like this?

Screenshot 2023-05-12 102401

muke1908 commented 1 year ago

yes but no curly braces. simply const BASE_URI = apiURL || (process.env.NODE_ENV === "production" ? 'https://chat-e2ee-2.azurewebsites.net' : '')

KalebArmbrust commented 1 year ago

Yes I missed that, sorry.

Screenshot 2023-05-12 102823

muke1908 commented 1 year ago

This is fine!

KalebArmbrust commented 1 year ago

@muke1908 Great, is there anything else or should I make a pull request?

muke1908 commented 1 year ago

yes, please create a PR. I’ll write comments there if any )