Swap urllib for yarl; make use of process.env

Signed-off-by: Antoine Mazeas <antoine@karthanis.net>
This commit is contained in:
Antoine Mazeas 2020-01-09 14:32:38 +01:00
parent 3b603a2180
commit 3aadf0c2a9
2 changed files with 4 additions and 5 deletions

View File

@ -42,7 +42,7 @@ class Main extends Component {
async getBasePath() { async getBasePath() {
try { try {
const resp = await fetch("./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 apiPathJson = await resp.json()

View File

@ -17,7 +17,7 @@ from typing import Tuple, Dict
import logging import logging
import asyncio import asyncio
import json import json
from urllib.parse import urlparse from yarl import URL
from aiohttp import web, hdrs from aiohttp import web, hdrs
from aiohttp.abc import AbstractAccessLogger from aiohttp.abc import AbstractAccessLogger
@ -136,9 +136,8 @@ class MaubotServer:
public_url = self.config["server.public_url"] public_url = self.config["server.public_url"]
base_path = self.config["server.base_path"] base_path = self.config["server.base_path"]
public_url_path = "" public_url_path = ""
if public_url != "": if public_url:
url_parts = urlparse(public_url) public_url_path = URL(public_url).path.rstrip("/")
public_url_path = url_parts.path.rstrip("/")
# assemble with base_path # assemble with base_path
api_path = f"{public_url_path}{base_path}" api_path = f"{public_url_path}{base_path}"