]> git.mxchange.org Git - fba.git/commitdiff
added config
authorEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 22 Apr 2022 18:56:58 +0000 (20:56 +0200)
committerEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 22 Apr 2022 18:56:58 +0000 (20:56 +0200)
README.md
api.py
config.defaults.json [new file with mode: 0644]
services/fedi_block_api.service

index 03fff23d0e7f4b1459b3199641b363fc06ac520d..9cda9e918f480283756528e4bc7027468eed4bd0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -16,8 +16,10 @@ sudo -Hu fba git clone https://gitlab.com/EnjuAihara/fedi-block-api.git /opt/fed
 cd /opt/fedi-block-api
 sudo -Hu fba pip3 install -r requirements.txt
 sudo -Hu fba cp blocks_preloaded.db blocks.db
+sudo -Hu fba cp config.defaults.json config.json
 ```
 
+
 ### Install the services
 
 ```bash
diff --git a/api.py b/api.py
index 0090f62d4a26512b26924dd0c44bbeb2ec6f8778..5f0bb53886726792900bda3eb25b41e4a2f51978 100644 (file)
--- a/api.py
+++ b/api.py
@@ -1,10 +1,15 @@
+import uvicorn
 from fastapi import FastAPI, Request, HTTPException, responses
 import sqlite3
 from hashlib import sha256
 from fastapi.templating import Jinja2Templates
 from requests import get
+from json import loads
 
-base_url = ""
+with open("config.json") as f:
+    config = loads(f.read())
+    base_url = config["base_url"]
+    port = config["port"]
 app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
 templates = Jinja2Templates(directory=".")
 
@@ -57,13 +62,16 @@ def blocked(domain: str = None):
 def index(request: Request, domain: str = None):
     if domain == "":
         return responses.RedirectResponse("/")
-    blocks = get(f"http://127.0.0.1:8069{base_url}/api?domain={domain}")
+    blocks = get(f"http://127.0.0.1:{port}{base_url}/api?domain={domain}")
     info = None
     if domain == None:
-        info = get(f"http://127.0.0.1:8069{base_url}/info")
+        info = get(f"http://127.0.0.1:{port}{base_url}/info")
         if not info.ok:
             raise HTTPException(status_code=info.status_code, detail=info.text)
         info = info.json()
     if not blocks.ok:
         raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
     return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks.json(), "info": info})
+
+if __name__ == "__main__":
+    uvicorn.run("api:app", host="127.0.0.1", port=port, log_level="info")
diff --git a/config.defaults.json b/config.defaults.json
new file mode 100644 (file)
index 0000000..d0fe2a9
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "base_url": "",
+    "port": 8069
+}
index f2e2456caa52d0102cd8d4397f74003f5e33357e..50f29d5a12cef4d68f08a33fa38c2465183047a5 100644 (file)
@@ -7,7 +7,7 @@ Restart=on-failure
 RestartSec=10
 User=fba
 WorkingDirectory=/opt/fedi-block-api
-ExecStart=uvicorn api:app --port 8069
+ExecStart=python3 api.py
 
 [Install]
 WantedBy=multi-user.target