add proxy support
This commit is contained in:
parent
e6c8ed5504
commit
fc3323faa5
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import yaml
|
||||
|
||||
from blib import Url
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Generic, TypeVar
|
||||
|
@ -96,6 +97,17 @@ class Config(dict[str, dict[str, Any]]):
|
|||
self.path.parent.mkdir(exist_ok = True, parents = True)
|
||||
|
||||
|
||||
@property
|
||||
def proxy_url(self) -> Url:
|
||||
return Url(
|
||||
domain = self.proxy_host,
|
||||
proto = self.proxy_type,
|
||||
port = self.proxy_port,
|
||||
username = self.proxy_user,
|
||||
password = self.proxy_pass
|
||||
)
|
||||
|
||||
|
||||
@property
|
||||
def sqlite_path(self) -> Path:
|
||||
return self.path.parent.joinpath("database.sqlite3")
|
||||
|
|
|
@ -20,6 +20,7 @@ from .translations import Translations
|
|||
|
||||
from basgi import (
|
||||
Application as App,
|
||||
Client,
|
||||
Request,
|
||||
Response,
|
||||
Template,
|
||||
|
@ -40,6 +41,10 @@ class Application(App[Request, RequestState, AppState]):
|
|||
|
||||
self.state.setup(cfg_path, language)
|
||||
self.error_handlers[HttpError] = self.handle_http_exception
|
||||
|
||||
if self.state.config.proxy_enabled:
|
||||
self.client = Client(self.name, self.state.config.proxy_url)
|
||||
|
||||
self.client.useragent = f"BarksharkSocial/{__version__} (https://{self.config.web_host})"
|
||||
|
||||
self.add_static(
|
||||
|
|
Loading…
Reference in a new issue