Skip to content

Commit

Permalink
static python website file updates
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-ji committed Sep 15, 2023
1 parent cdcbb42 commit b1eb4a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
40 changes: 30 additions & 10 deletions run_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import subprocess
import socket
import os
import platform
import math
import random
import webbrowser

OS_TYPE = platform.system()

PORT = 5000
# get current directory and set it as the directory to serve
DIRECTORY = os.path.dirname(os.path.realpath(__file__)) + "/dist"
DIRECTORY = os.path.dirname(os.path.realpath(__file__)) + "/dist/"

def kill_port_unix(port):
command = f"lsof -i :{port} -t"
Expand Down Expand Up @@ -35,17 +41,31 @@ def kill_port_windows(port):

# If port is in use, suggest using --force option
if port_in_use:
force_port = input(f"Port {PORT} is already in use. Try to close the port and continue [Y/n]? ")
if force_port.lower() == "y":
kill_port_unix(PORT)
kill_port_windows(PORT)
else:
exit(1)
force_port = input(f"Port {PORT} is already in use. Try to close the port and continue [Y/n]? ")
if force_port.lower() == "y":
if OS_TYPE == "Windows":
kill_port_windows(PORT)
else:
kill_port_unix(PORT)
else:
exit(1)

class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)

with socketserver.TCPServer(("", PORT), Handler) as httpd:
print(f'Serving at port {PORT}. Visit http://localhost:{PORT}/index.html')
httpd.serve_forever()
def start_server(port):
try:
with socketserver.ThreadingTCPServer(("", port), Handler) as httpd:
print(f'Serving at port {port}. Visit http://localhost:{port}. To stop, press Ctrl+C (multiple times if needed)')
webbrowser.open(f"http://localhost:{port}")
httpd.serve_forever()
except KeyboardInterrupt:
print("Stopping server...")
httpd.shutdown()
httpd.server_close()

try:
start_server(PORT)
except OSError as e:
start_server(6802 + math.floor(random.random() * 15))
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class App extends Component {

initRefGenomes = () => {
const preloadRefInterval = setInterval(() => {
if (this.state.refGenomes.size > 0) {
if (this.state.refGenomes?.size > 0) {
clearInterval(preloadRefInterval);
const preloadRefOptions = [];
for (const REF_NAME_MAP of Object.entries(REF_NAMES)) {
Expand Down

0 comments on commit b1eb4a0

Please sign in to comment.