generated from nathanwoodburn/python-webserver-template
feat: Create api server for hs-anyone
All checks were successful
Build Docker / BuildImage (push) Successful in 45s
All checks were successful
Build Docker / BuildImage (push) Successful in 45s
This commit is contained in:
parent
613007f436
commit
1f2dbe0e99
26
server.py
26
server.py
@ -15,6 +15,7 @@ import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import dotenv
|
||||
import subprocess
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
@ -67,6 +68,31 @@ def wellknown(path):
|
||||
req.content, 200, {"Content-Type": req.headers["Content-Type"]}
|
||||
)
|
||||
|
||||
@app.route("/renew", methods=["POST"])
|
||||
def renew():
|
||||
# Get post data
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({"error": "No data provided"}), 400
|
||||
|
||||
# Get the domain
|
||||
domain = data.get("domain")
|
||||
if not domain:
|
||||
return jsonify({"error": "No domain provided"}), 400
|
||||
|
||||
# Get path from env
|
||||
path = os.getenv("PATH")
|
||||
wallet = os.getenv("WALLET")
|
||||
apiKEY = os.getenv("API_KEY")
|
||||
if not path:
|
||||
return jsonify({"error": "No HS-ANYONE found"}), 400
|
||||
|
||||
# Run the renewal
|
||||
output = subprocess.run(["node", path, "renew", domain, "--wallet", wallet, "--network", "main", "--broadcast", "true", "--apikey", apiKEY], capture_output=True, text=True)
|
||||
return jsonify({"output": output.stdout,"error": output.stderr}), 200
|
||||
|
||||
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user