diff --git a/config/config.yaml b/config/config.yaml index 09fa0e5..042ccfd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -2,11 +2,11 @@ Server: host: 127.0.0.1 port: 8000 cors: False + static_folder: frontend/build Web: host: 127.0.0.1 port: 8000 - static_folder: frontend/build Database: username: foo diff --git a/scripts/run.sh b/scripts/run.sh index 2864606..d9faa87 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -3,4 +3,4 @@ cd frontend npm run build cd .. -poetry run shortenit +poetry run shortenit "$@" diff --git a/shortenit/main.py b/shortenit/main.py index b3258a1..1963860 100644 --- a/shortenit/main.py +++ b/shortenit/main.py @@ -54,8 +54,7 @@ def main() -> typing.NoReturn: def shorten_it(config: dict, session: Session, data: str, ttl: int): - shortener_config = config.get("Shortener", None) - shortener = Shortener(session, shortener_config) + shortener = Shortener(session, config) identifier = shortener.generate_uuid() if identifier: try: diff --git a/shortenit/web.py b/shortenit/web.py index 3f662bc..50aa7f7 100644 --- a/shortenit/web.py +++ b/shortenit/web.py @@ -22,6 +22,7 @@ class Web: self.app.run(host=self.host, port=self.port, debug=self.debug) def init(self): + server_config = self.handler.configuration.get("Server", None) self.app = Flask(__name__) self.setup_routes() if server_config and server_config.get("cors", False): @@ -58,6 +59,9 @@ class SiteHandler: {trafaret.Key("url"): trafaret.URL, trafaret.Key("timestamp"): trafaret.Int} ) + def _get_server_config(self): + return self.configuration.get("Server", None) + def shortenit(self): data = request.get_json() try: @@ -69,7 +73,10 @@ class SiteHandler: abort(400) try: short_url = self.shorten_url( - self.configuration, self.database, data["url"], data["timestamp"] + self.configuration.get("Shortener", None), + self.database, + data["url"], + data["timestamp"], ) except KeyError as e: self.logger.error(e) @@ -103,7 +110,7 @@ class SiteHandler: try: project_root = Path(__file__).parent.parent static_folder = ( - f"{project_root}/" + self.configuration.get("Web")["static_folder"] + f"{project_root}/" + self._get_server_config()["static_folder"] ) if check_file(static_folder + "/" + path): return send_from_directory(static_folder, path)