feat: Redirect empty domain to main server
This commit is contained in:
parent
114818f294
commit
ec53b5862b
@ -21,6 +21,7 @@ services:
|
|||||||
DB_USER: main
|
DB_USER: main
|
||||||
DB_PASSWORD: your-db-password
|
DB_PASSWORD: your-db-password
|
||||||
DB_NAME: main
|
DB_NAME: main
|
||||||
|
CITY_DOMAIN: exampledomainnathan1
|
||||||
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
||||||
|
|
||||||
sites:
|
sites:
|
||||||
@ -32,6 +33,7 @@ services:
|
|||||||
DB_USER: main
|
DB_USER: main
|
||||||
DB_PASSWORD: your-db-password
|
DB_PASSWORD: your-db-password
|
||||||
DB_NAME: main
|
DB_NAME: main
|
||||||
|
MAIN_DOMAIN: cities.hnshosting.au
|
||||||
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
WORKERS: 2 # number of workers to run (should be 2 * number of cores)
|
||||||
|
|
||||||
db:
|
db:
|
||||||
|
@ -24,7 +24,7 @@ def get_website_data(domain):
|
|||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
if data == []:
|
if data == []:
|
||||||
return "No data found for this domain"
|
return ""
|
||||||
|
|
||||||
parsed = data[0][2]
|
parsed = data[0][2]
|
||||||
parsed = json.loads(parsed)
|
parsed = json.loads(parsed)
|
||||||
|
@ -12,21 +12,20 @@ import website
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
|
main_domain = "cities.hnshosting.au"
|
||||||
|
if os.getenv('MAIN_DOMAIN') != None:
|
||||||
|
main_domain = os.getenv('MAIN_DOMAIN')
|
||||||
|
|
||||||
#Assets routes
|
#Assets routes
|
||||||
@app.route('/assets/<path:path>')
|
@app.route('/assets/<path:path>')
|
||||||
def assets(path):
|
def assets(path):
|
||||||
return send_from_directory('templates/assets', path)
|
return send_from_directory('templates/assets', path)
|
||||||
|
|
||||||
#! TODO make prettier
|
|
||||||
def error(message):
|
|
||||||
return jsonify({'success': False, 'message': message}), 400
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
host = request.host
|
host = request.host
|
||||||
if len(host.split('.')) != 2:
|
if len(host.split('.')) != 2:
|
||||||
return error('Invalid domain')
|
return redirect('https://'+main_domain)
|
||||||
host = host.split('.')[0]
|
host = host.split('.')[0]
|
||||||
|
|
||||||
# Get website data
|
# Get website data
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
|
from flask import Flask, make_response, redirect, render_template_string, request, jsonify, render_template, send_from_directory
|
||||||
from bs4 import BeautifulSoup
|
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):
|
def render(data):
|
||||||
if data == "":
|
if data == "":
|
||||||
return "No data found for this domain"
|
return redirect("https://" + main_domain + '/claim?domain=' + request.host.split('.')[0])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
soup = BeautifulSoup(data, 'html.parser')
|
soup = BeautifulSoup(data, 'html.parser')
|
||||||
|
Loading…
Reference in New Issue
Block a user