Mattermost, Inc.

How to connect local webapp to remote server

Hello, i have deployed mattermost-server to my own server on DigitalOcean, and then i cloned mattermost-webapp. My question is how to connect local webapp at http://localhost:9005 to remote server API. Thank you :smiley:
After finding the answer from mattermost community, i knew an alternative way using Charles: but i think this is not convenient, official way.

After some hours researching, i found a way to set the remote API in components/root/root.jsx

 constructor(props) {
        super(props);
        this.currentCategoryFocus = 0;
        this.currentSidebarFocus = 0;

        // Redux
        // setUrl(getSiteURL());
        setUrl('http://this.is.my.ip');

and in actions/websocket_actions.jsx

   const config = getConfig(getState());
    let connUrl = '';
    if (config.WebsocketURL) {
        connUrl = config.WebsocketURL;
    } else {
        // connUrl = new URL(getSiteURL());
        connUrl = new URL('http://this.is.my.ip');

Everything seems work fine but it always be logged out after I refreshed page.
image
Does anyone get this problem? :frowning:

You could ask about this on our Community server’s Peer-to-peer channel here. I’m not sure how to help with this issue, but one of our developers or other community members might.

1 Like

I have posted to Peer-to-peer but got no help :frowning:

I found the problem, when we refresh page, we load MMUSERID from document.cookie, but it belong to domain this.is.my.ip, not localhost, so we can not get MMUSERID, so we have to login again.
I haven’t found anyway workaround :frowning:

@huy-lv, I’m not sure there is an “official supported” way to do this. The Charles approach will work, but agree it’s not super convenient. There is also the npm run dev-server option which you can hack to point at an arbitrary upstream, but I don’t know how well it works.

Feel free to reach out on https://community-daily.mattermost.com/core/channels/developers to see if any of the other developers have insights to offer :slight_smile: