Skip to content

Commit

Permalink
feat: allow changing server address to remote
Browse files Browse the repository at this point in the history
  • Loading branch information
Crissium committed Oct 2, 2023
1 parent e0811a7 commit d688512
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions http_server/change_server_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
import socket
import re
import os
import sys
from http_server import dist_dir


if __name__ == '__main__':
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
try:
s.connect(('10.254.254.254', 1))
ip = s.getsockname()[0]
except:
ip = '127.0.0.1'
finally:
s.close()

address_pattern = re.compile(r'http://[^:]+:2628/api')
replacement = 'http://%s:2628/api' % ip

if len(sys.argv) > 1:
replacement = sys.argv[1]
else:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
try:
s.connect(('10.254.254.254', 1))
ip = s.getsockname()[0]
except:
ip = '127.0.0.1'
finally:
s.close()
replacement = 'http://%s:2628/api' % ip

for filename in os.listdir(os.path.join(dist_dir, 'static', 'js')):
full_filename = os.path.join(dist_dir, 'static', 'js', filename)
Expand Down

0 comments on commit d688512

Please sign in to comment.