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
6 changed files with 7 additions and 19 deletions
|
@ -52,11 +52,9 @@ class Config(BaseFileConfig):
|
||||||
copy("server.port")
|
copy("server.port")
|
||||||
copy("server.public_url")
|
copy("server.public_url")
|
||||||
copy("server.listen")
|
copy("server.listen")
|
||||||
copy("server.base_path")
|
|
||||||
copy("server.ui_base_path")
|
copy("server.ui_base_path")
|
||||||
copy("server.plugin_base_path")
|
copy("server.plugin_base_path")
|
||||||
copy("server.override_resource_path")
|
copy("server.override_resource_path")
|
||||||
copy("server.appservice_base_path")
|
|
||||||
shared_secret = self["server.unshared_secret"]
|
shared_secret = self["server.unshared_secret"]
|
||||||
if shared_secret is None or shared_secret == "generate":
|
if shared_secret is None or shared_secret == "generate":
|
||||||
base["server.unshared_secret"] = self._new_token()
|
base["server.unshared_secret"] = self._new_token()
|
||||||
|
|
|
@ -55,8 +55,6 @@ server:
|
||||||
port: 29316
|
port: 29316
|
||||||
# Public base URL where the server is visible.
|
# Public base URL where the server is visible.
|
||||||
public_url: https://example.com
|
public_url: https://example.com
|
||||||
# The base management API path.
|
|
||||||
base_path: /_matrix/maubot/v1
|
|
||||||
# The base path for the UI.
|
# The base path for the UI.
|
||||||
ui_base_path: /_matrix/maubot
|
ui_base_path: /_matrix/maubot
|
||||||
# The base path for plugin endpoints. The instance ID will be appended directly.
|
# 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.
|
# Override path from where to load UI resources.
|
||||||
# Set to false to using pkg_resources to find the path.
|
# Set to false to using pkg_resources to find the path.
|
||||||
override_resource_path: false
|
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.
|
# The shared secret to sign API access tokens.
|
||||||
# Set to "generate" to generate and save a new token at startup.
|
# Set to "generate" to generate and save a new token at startup.
|
||||||
unshared_secret: generate
|
unshared_secret: generate
|
||||||
|
|
|
@ -184,8 +184,7 @@ async def _do_sso(req: AuthRequestInfo) -> web.Response:
|
||||||
cfg = get_config()
|
cfg = get_config()
|
||||||
public_url = (
|
public_url = (
|
||||||
URL(cfg["server.public_url"])
|
URL(cfg["server.public_url"])
|
||||||
/ cfg["server.base_path"].lstrip("/")
|
/ "_matrix/maubot/v1/client/auth_external_sso/complete"
|
||||||
/ "client/auth_external_sso/complete"
|
|
||||||
/ waiter_id
|
/ waiter_id
|
||||||
)
|
)
|
||||||
sso_url = req.client.api.base_url.with_path(str(Path.v3.login.sso.redirect)).with_query(
|
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
|
@web.middleware
|
||||||
async def auth(request: web.Request, handler: Handler) -> web.Response:
|
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 (
|
if (
|
||||||
subpath.startswith("/auth/")
|
subpath.startswith("/auth/")
|
||||||
or subpath.startswith("/client/auth_external_sso/complete/")
|
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", {
|
const resp = await fetch(process.env.PUBLIC_URL + "/paths.json", {
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
})
|
})
|
||||||
const apiPathJson = await resp.json()
|
const apiPaths = await resp.json()
|
||||||
const apiPath = apiPathJson.api_path
|
api.setBasePath(apiPaths.api_path)
|
||||||
api.setBasePath(`${apiPath}`)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to get API path:", err)
|
console.error("Failed to get API path:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class MaubotServer:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.setup_appservice()
|
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_instance_subapps()
|
||||||
self.setup_management_ui()
|
self.setup_management_ui()
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class MaubotServer:
|
||||||
self.app.router.register_resource(resource)
|
self.app.router.register_resource(resource)
|
||||||
|
|
||||||
def setup_appservice(self) -> None:
|
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)
|
self.add_route(Method.PUT, as_path.transactions, self.handle_transaction)
|
||||||
|
|
||||||
def setup_management_ui(self) -> None:
|
def setup_management_ui(self) -> None:
|
||||||
|
@ -140,16 +140,12 @@ class MaubotServer:
|
||||||
f"{ui_base}/{file}", lambda _: web.Response(body=data, content_type=mime)
|
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"]
|
public_url = self.config["server.public_url"]
|
||||||
base_path = self.config["server.base_path"]
|
|
||||||
public_url_path = ""
|
public_url_path = ""
|
||||||
if public_url:
|
if public_url:
|
||||||
public_url_path = URL(public_url).path.rstrip("/")
|
public_url_path = URL(public_url).path.rstrip("/")
|
||||||
|
|
||||||
# assemble with base_path
|
api_path = f"{public_url_path}/_matrix/maubot/v1"
|
||||||
api_path = f"{public_url_path}{base_path}"
|
|
||||||
|
|
||||||
path_prefix_response_body = json.dumps({"api_path": api_path.rstrip("/")})
|
path_prefix_response_body = json.dumps({"api_path": api_path.rstrip("/")})
|
||||||
self.app.router.add_get(
|
self.app.router.add_get(
|
||||||
|
|
Loading…
Reference in a new issue