Drop support for custom API paths
Changing the base public URL is still possible (which may be useful if someone wants to use a reverse proxy without adding subdomains). Fixes #195
This commit is contained in:
parent
6fd8f7ed00
commit
e99a13a391
@ -52,11 +52,9 @@ class Config(BaseFileConfig):
|
||||
copy("server.port")
|
||||
copy("server.public_url")
|
||||
copy("server.listen")
|
||||
copy("server.base_path")
|
||||
copy("server.ui_base_path")
|
||||
copy("server.plugin_base_path")
|
||||
copy("server.override_resource_path")
|
||||
copy("server.appservice_base_path")
|
||||
shared_secret = self["server.unshared_secret"]
|
||||
if shared_secret is None or shared_secret == "generate":
|
||||
base["server.unshared_secret"] = self._new_token()
|
||||
|
@ -55,8 +55,6 @@ server:
|
||||
port: 29316
|
||||
# Public base URL where the server is visible.
|
||||
public_url: https://example.com
|
||||
# The base management API path.
|
||||
base_path: /_matrix/maubot/v1
|
||||
# The base path for the UI.
|
||||
ui_base_path: /_matrix/maubot
|
||||
# The base path for plugin endpoints. The instance ID will be appended directly.
|
||||
@ -64,8 +62,6 @@ server:
|
||||
# Override path from where to load UI resources.
|
||||
# Set to false to using pkg_resources to find the path.
|
||||
override_resource_path: false
|
||||
# The base appservice API path. Use / for legacy appservice API and /_matrix/app/v1 for v1.
|
||||
appservice_base_path: /_matrix/app/v1
|
||||
# The shared secret to sign API access tokens.
|
||||
# Set to "generate" to generate and save a new token at startup.
|
||||
unshared_secret: generate
|
||||
|
@ -184,8 +184,7 @@ async def _do_sso(req: AuthRequestInfo) -> web.Response:
|
||||
cfg = get_config()
|
||||
public_url = (
|
||||
URL(cfg["server.public_url"])
|
||||
/ cfg["server.base_path"].lstrip("/")
|
||||
/ "client/auth_external_sso/complete"
|
||||
/ "_matrix/maubot/v1/client/auth_external_sso/complete"
|
||||
/ waiter_id
|
||||
)
|
||||
sso_url = req.client.api.base_url.with_path(str(Path.v3.login.sso.redirect)).with_query(
|
||||
|
@ -29,7 +29,7 @@ log = logging.getLogger("maubot.server")
|
||||
|
||||
@web.middleware
|
||||
async def auth(request: web.Request, handler: Handler) -> web.Response:
|
||||
subpath = request.path[len(get_config()["server.base_path"]) :]
|
||||
subpath = request.path[len("/_matrix/maubot/v1") :]
|
||||
if (
|
||||
subpath.startswith("/auth/")
|
||||
or subpath.startswith("/client/auth_external_sso/complete/")
|
||||
|
@ -45,9 +45,8 @@ class Main extends Component {
|
||||
const resp = await fetch(process.env.PUBLIC_URL + "/paths.json", {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
const apiPathJson = await resp.json()
|
||||
const apiPath = apiPathJson.api_path
|
||||
api.setBasePath(`${apiPath}`)
|
||||
const apiPaths = await resp.json()
|
||||
api.setBasePath(apiPaths.api_path)
|
||||
} catch (err) {
|
||||
console.error("Failed to get API path:", err)
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class MaubotServer:
|
||||
self.config = config
|
||||
|
||||
self.setup_appservice()
|
||||
self.app.add_subapp(config["server.base_path"], management_api)
|
||||
self.app.add_subapp("/_matrix/maubot/v1", management_api)
|
||||
self.setup_instance_subapps()
|
||||
self.setup_management_ui()
|
||||
|
||||
@ -93,7 +93,7 @@ class MaubotServer:
|
||||
self.app.router.register_resource(resource)
|
||||
|
||||
def setup_appservice(self) -> None:
|
||||
as_path = PathBuilder(self.config["server.appservice_base_path"])
|
||||
as_path = PathBuilder("/_matrix/appservice/v1")
|
||||
self.add_route(Method.PUT, as_path.transactions, self.handle_transaction)
|
||||
|
||||
def setup_management_ui(self) -> None:
|
||||
@ -140,16 +140,12 @@ class MaubotServer:
|
||||
f"{ui_base}/{file}", lambda _: web.Response(body=data, content_type=mime)
|
||||
)
|
||||
|
||||
# also set up a resource path for the public url path prefix config
|
||||
# cut the prefix path from public_url
|
||||
public_url = self.config["server.public_url"]
|
||||
base_path = self.config["server.base_path"]
|
||||
public_url_path = ""
|
||||
if public_url:
|
||||
public_url_path = URL(public_url).path.rstrip("/")
|
||||
|
||||
# assemble with base_path
|
||||
api_path = f"{public_url_path}{base_path}"
|
||||
api_path = f"{public_url_path}/_matrix/maubot/v1"
|
||||
|
||||
path_prefix_response_body = json.dumps({"api_path": api_path.rstrip("/")})
|
||||
self.app.router.add_get(
|
||||
|
Loading…
Reference in New Issue
Block a user