2022-07-27 16:45:17 +02:00
|
|
|
import click
|
2022-07-08 10:24:54 +02:00
|
|
|
import uvicorn
|
|
|
|
|
2022-11-19 21:41:37 +01:00
|
|
|
from lnbits.settings import FORWARDED_ALLOW_IPS, HOST, PORT
|
2022-08-03 13:16:50 +02:00
|
|
|
|
2022-07-08 10:24:54 +02:00
|
|
|
|
2022-08-03 13:16:50 +02:00
|
|
|
@click.command(
|
|
|
|
context_settings=dict(
|
|
|
|
ignore_unknown_options=True,
|
|
|
|
allow_extra_args=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@click.option("--port", default=PORT, help="Port to listen on")
|
2022-11-30 15:14:31 +01:00
|
|
|
@click.option("--host", default=HOST, help="Host to run LNbits on")
|
2022-11-19 21:41:37 +01:00
|
|
|
@click.option(
|
|
|
|
"--forwarded-allow-ips", default=FORWARDED_ALLOW_IPS, help="Allowed proxy servers"
|
|
|
|
)
|
2022-08-03 13:16:50 +02:00
|
|
|
@click.option("--ssl-keyfile", default=None, help="Path to SSL keyfile")
|
|
|
|
@click.option("--ssl-certfile", default=None, help="Path to SSL certificate")
|
|
|
|
@click.pass_context
|
2022-11-19 21:41:37 +01:00
|
|
|
def main(
|
|
|
|
ctx,
|
|
|
|
port: int,
|
|
|
|
host: str,
|
|
|
|
forwarded_allow_ips: str,
|
|
|
|
ssl_keyfile: str,
|
|
|
|
ssl_certfile: str,
|
|
|
|
):
|
2022-07-08 10:24:54 +02:00
|
|
|
"""Launched with `poetry run lnbits` at root level"""
|
2022-08-03 13:16:50 +02:00
|
|
|
# this beautiful beast parses all command line arguments and passes them to the uvicorn server
|
2022-08-04 16:37:48 +02:00
|
|
|
d = dict()
|
|
|
|
for a in ctx.args:
|
|
|
|
item = a.split("=")
|
|
|
|
if len(item) > 1: # argument like --key=value
|
|
|
|
print(a, item)
|
|
|
|
d[item[0].strip("--").replace("-", "_")] = (
|
|
|
|
int(item[1]) # need to convert to int if it's a number
|
|
|
|
if item[1].isdigit()
|
|
|
|
else item[1]
|
2022-08-03 13:16:50 +02:00
|
|
|
)
|
2022-08-04 16:37:48 +02:00
|
|
|
else:
|
|
|
|
d[a.strip("--")] = True # argument like --key
|
|
|
|
|
2022-08-03 13:16:50 +02:00
|
|
|
config = uvicorn.Config(
|
|
|
|
"lnbits.__main__:app",
|
|
|
|
port=port,
|
|
|
|
host=host,
|
2022-11-19 21:41:37 +01:00
|
|
|
forwarded_allow_ips=forwarded_allow_ips,
|
2022-08-03 13:16:50 +02:00
|
|
|
ssl_keyfile=ssl_keyfile,
|
|
|
|
ssl_certfile=ssl_certfile,
|
|
|
|
**d
|
|
|
|
)
|
|
|
|
server = uvicorn.Server(config)
|
|
|
|
server.run()
|
2022-07-08 10:24:54 +02:00
|
|
|
|
2022-07-27 16:45:17 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-07-08 10:24:54 +02:00
|
|
|
main()
|