[~] Refactor
This commit is contained in:
parent
f99cf5d304
commit
e2bbae5b99
@ -1056,12 +1056,25 @@ def http_server(argv):
|
||||
action='store_true',
|
||||
default=False,
|
||||
)
|
||||
parser.add_option(
|
||||
'--token',
|
||||
dest='token',
|
||||
type=str,
|
||||
default=None,
|
||||
)
|
||||
parser.add_option(
|
||||
'--port',
|
||||
dest='port',
|
||||
type='int',
|
||||
default=80,
|
||||
)
|
||||
parser.add_option(
|
||||
'-H', '--header',
|
||||
dest='response_headers',
|
||||
type='str',
|
||||
action='append',
|
||||
default=[],
|
||||
)
|
||||
parser.add_option(
|
||||
'--host',
|
||||
dest='host',
|
||||
@ -1092,17 +1105,29 @@ def http_server(argv):
|
||||
if options.public:
|
||||
location_section = 'location / {%s}' % index_section
|
||||
else:
|
||||
token = os.urandom(16).hex()
|
||||
if options.token is None:
|
||||
options.token = os.urandom(16).hex()
|
||||
|
||||
if not options.prefix is None:
|
||||
token = options.prefix + token
|
||||
path = options.prefix + options.token
|
||||
else:
|
||||
path = options.token
|
||||
|
||||
print(
|
||||
'access url is http://%s:%d/%s/' % (
|
||||
options.host,
|
||||
options.port,
|
||||
token,
|
||||
path,
|
||||
)
|
||||
)
|
||||
|
||||
assert all([
|
||||
not re.compile(
|
||||
r'^[A-Za-z-]+ [a-z0-9A-Z-\.]+$'
|
||||
).match(o) is None
|
||||
for o in options.response_headers
|
||||
])
|
||||
|
||||
location_section = (
|
||||
'location / {'
|
||||
'deny all;'
|
||||
@ -1110,8 +1135,16 @@ def http_server(argv):
|
||||
'location /%s/ {'
|
||||
'alias /app/;'
|
||||
'%s'
|
||||
'%s'
|
||||
'}'
|
||||
) % (token, index_section)
|
||||
) % (
|
||||
path,
|
||||
'\n'.join([
|
||||
'add_header %s;' % o
|
||||
for o in options.response_headers
|
||||
]),
|
||||
index_section
|
||||
)
|
||||
subprocess.check_call(
|
||||
r'''
|
||||
sudo docker run \
|
||||
|
Loading…
Reference in New Issue
Block a user