feat: Redirect empty domain to main server

This commit is contained in:
Nathan Woodburn 2023-11-09 12:51:35 +11:00
parent 114818f294
commit ec53b5862b
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
4 changed files with 14 additions and 7 deletions

View File

@ -21,6 +21,7 @@ services:
DB_USER: main
DB_PASSWORD: your-db-password
DB_NAME: main
CITY_DOMAIN: exampledomainnathan1
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
sites:
@ -32,6 +33,7 @@ services:
DB_USER: main
DB_PASSWORD: your-db-password
DB_NAME: main
MAIN_DOMAIN: cities.hnshosting.au
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
db:

View File

@ -24,7 +24,7 @@ def get_website_data(domain):
connection.close()
if data == []:
return "No data found for this domain"
return ""
parsed = data[0][2]
parsed = json.loads(parsed)

View File

@ -12,21 +12,20 @@ import website
app = Flask(__name__)
dotenv.load_dotenv()
main_domain = "cities.hnshosting.au"
if os.getenv('MAIN_DOMAIN') != None:
main_domain = os.getenv('MAIN_DOMAIN')
#Assets routes
@app.route('/assets/<path:path>')
def assets(path):
return send_from_directory('templates/assets', path)
#! TODO make prettier
def error(message):
return jsonify({'success': False, 'message': message}), 400
@app.route('/')
def index():
host = request.host
if len(host.split('.')) != 2:
return error('Invalid domain')
return redirect('https://'+main_domain)
host = host.split('.')[0]
# Get website data

View File

@ -1,9 +1,15 @@
from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
from bs4 import BeautifulSoup
import os
import dotenv
main_domain = "cities.hnshosting.au"
if os.getenv('MAIN_DOMAIN') != None:
main_domain = os.getenv('MAIN_DOMAIN')
def render(data):
if data == "":
return "No data found for this domain"
return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0])
try:
soup = BeautifulSoup(data, 'html.parser')