Converted to bottle, added proper redirect
This commit is contained in:
parent
ffd7fb37af
commit
3895fcb8ba
1 changed files with 23 additions and 10 deletions
33
chainlink.py
33
chainlink.py
|
@ -1,26 +1,39 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""Utilize crypto domains DNS and either redirect, or display information."""
|
"""Utilize crypto domains DNS and either redirect, or display information."""
|
||||||
from flask import Flask, redirect, url_for
|
from bottle import Bottle, run, response, request
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
VERSION = '0.0.1'
|
VERSION = '0.0.1'
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Bottle()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
return 'There is nothing here'
|
host = request.get_header('host')
|
||||||
|
return f'specify domain in URL like {host}/domain.crypto'
|
||||||
|
|
||||||
|
|
||||||
@app.route("/<string:domain>")
|
@app.route("/<domain>")
|
||||||
def showdomain(domain):
|
def showdomain(domain):
|
||||||
redirect = requests.get(f'https://unstoppabledomains.com/api/v1/{domain}')
|
apiurl =f'https://unstoppabledomains.com/api/v1/{domain}'
|
||||||
if redirect.status_code == 200:
|
redirect = requests.get(apiurl)
|
||||||
body = json.loads(redirect.content)
|
try:
|
||||||
redirect_url = body['ipfs']['redirect_domain']
|
if redirect.status_code == 200:
|
||||||
return f'<body onload="window.location = \'{redirect_url}\'"><p></body>'
|
body = json.loads(redirect.content)
|
||||||
|
print(body)
|
||||||
|
redirect_url = body['ipfs']['redirect_domain']
|
||||||
|
# TODO: Add handler for the ipfs vs redirect
|
||||||
|
# if body['ipfs']['html']:
|
||||||
|
# print('We have html')
|
||||||
|
response.status = 302
|
||||||
|
response.set_header('Location',redirect_url)
|
||||||
|
else:
|
||||||
|
return f'Error making call to {apiurl} for {domain}'
|
||||||
|
except KeyError:
|
||||||
|
return f'Did not find a redirect for {domain}'
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
run(app, host='localhost', port='5000', reloader=True)
|
||||||
|
|
Loading…
Reference in a new issue