synapse-admin icon indicating copy to clipboard operation
synapse-admin copied to clipboard

Setting default homeserver when using static files?

Open wagner-intevation opened this issue 3 years ago • 5 comments

Is there any way to set a default homeserver, when using the installation variant 1 ("Download the tarball and serve with any webserver")?

I already tried adding REACT_APP_SERVER to the arrary in synapse-admin/static/js/main.73885304.chunk.js which also defines the PUBLIC_URL, but that has no effect.

wagner-intevation avatar Sep 05 '22 16:09 wagner-intevation

By now there is no option to set a default homeserver for the installation.

awesome-michael avatar Sep 06 '22 07:09 awesome-michael

@wagner-intevation Maybe change the issue title also to "default homeserver".

This would be really great, because when you self host synapse and synapse admin, most of the time (if not even always) you are using it only with your local server. This would save some typing effort on every login. And might even help to disclose the URL to the admin API?!

efelon avatar Sep 22 '22 12:09 efelon

@wagner-intevation Maybe change the issue title also to "default homeserver".

Oops, that was a typo on my side and I didn't realize it until now. Thanks for the pointer.

As a workaround, I built the app with docker using PUBLIC_URL and REACT_APP_SERVER, extracted the data from /usr/share/nginx/html/ inside the container and served that statically with the existing web server.

wagner-intevation avatar Sep 22 '22 13:09 wagner-intevation

Docker is no option for me. I hope some more people also find this option useful and give their thumbs up.

efelon avatar Sep 23 '22 08:09 efelon

Docker is no option for me.

I used Docker only for building the app. Instead you can also use these commands directly on your host machine:

yarn --network-timeout=100000 install
RUN PUBLIC_URL=$PUBLIC_URL REACT_APP_SERVER=$REACT_APP_SERVER yarn build

See Dockerfile

wagner-intevation avatar Sep 23 '22 10:09 wagner-intevation

I made a handful Jupyter notebook to build static website with custom homeserver set. Run online: https://colab.research.google.com/drive/18oo2M_4ke7ktO2rjwcOBWFyo5iNYLiks?usp=sharing (yes, I know, a gist soon to follow...)

.ipynb file
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Build Synapse-Admin with custom URL\n",
        "\n",
        "This notebook will help you build your Synapse Admin with homeserver URL locked.\n",
        "\n",
        "Please follow the following steps in order to build your own page.\n",
        "\n",
        "## How to use?\n",
        "1. Fill the form (if required)\n",
        "2. Press the `Run` button on the left of the card.\n",
        "3. Before running the next step, make sure the previous completed successfully (there is a green checkmark instead of the `Run` button)"
      ],
      "metadata": {
        "id": "l5HCCOrYwCbg"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Get all dependencies {display-mode: \"form\"}\n",
        "from google.colab import runtime, files\n",
        "import tarfile\n",
        "import zipfile\n",
        "\n",
        "!curl -fsSL https://deb.nodesource.com/setup_20.x | bash -\n",
        "!apt install -y nodejs git\n",
        "!npm -g i yarn"
      ],
      "metadata": {
        "id": "sqoKbVFyygPc"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Aquire Synapse's Admin UI source code {display-mode: \"form\"}\n",
        "# @markdown This step will get the source code of the Synapse-Admin source code<br>Use tag `latest` for the latest stable release, otherwise a branch. If you don't know what I mean, leave this alone.\n",
        "tag = 'latest'  # @param {type: \"string\"}\n",
        "\n",
        "import requests\n",
        "import os\n",
        "\n",
        "if tag==\"latest\":\n",
        "  h = requests.get(\"https://api.github.com/repos/Awesome-Technologies/synapse-admin/releases/latest\").json()\n",
        "  tag=h[\"name\"]\n",
        "!git clone -b {tag} https://github.com/Awesome-Technologies/synapse-admin.git\n",
        "os.chdir(\"synapse-admin\")"
      ],
      "metadata": {
        "id": "YphdnJjVwkS_"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Enter details for your admin page {display-mode: \"form\"}\n",
        "# @markdown This will inject the index page with a small style to hide to hide the homeserver URL input field. Looks good to my eye.\n",
        "hide_homeserver_url = False # @param {type:'boolean'}\n",
        "# @markdown Now input the homeserver URL (WITH `http://` or `https://`)\n",
        "homeserver_url = \"https://matrix.myserver.com\" # @param {type:'string'}\n",
        "# @markdown Now one final thing: the path on which you will host the admin panel on.<br>May also be `/`. Must also begin with `/`\n",
        "path = \"/matrixadmin\" # @param {type:'string'}\n",
        "!node -v\n",
        "!yarn install\n",
        "if not (homeserver_url.startswith(\"http://\") or homeserver_url.startswith(\"https://\")):\n",
        "  raise Exception(\"The homeserver URL MUST start with http:// or https://\")\n",
        "if not path.startswith(\"/\"):\n",
        "  raise Exception(\"The path MUST start with a /\")\n",
        "!REACT_APP_SERVER={homeserver_url} PATH_URL={path} yarn build\n",
        "os.chdir(\"build\")\n",
        "if (hide_homeserver_url):\n",
        "  with open(\"index.html\",\"a\") as f:\n",
        "    f.write(\"<style>#root > div > form > div > div > div.form.MuiBox-root.css-0 > div:nth-child(4) {display:none}</style>\")\n"
      ],
      "metadata": {
        "id": "T4_S-wsl11Ag"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}

MajliTech avatar Mar 10 '24 22:03 MajliTech