-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
39 lines (27 loc) · 1.07 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from os import getenv
from fastapi import Depends, Request
from fastapi.templating import Jinja2Templates
from pyngrok import conf, ngrok # type: ignore
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from . import ngrok_ext, ngrok_renderer
templates = Jinja2Templates(directory="templates")
def log_event_callback(log):
string = str(log)
string2 = string[string.find('url="https') : string.find('url="https') + 80]
if string2:
string3 = string2
string4 = string3[4:]
global string5
string5 = string4.replace('"', "")
conf.get_default().log_event_callback = log_event_callback
ngrok_authtoken = getenv("NGROK_AUTHTOKEN")
if ngrok_authtoken is not None:
ngrok.set_auth_token(ngrok_authtoken)
port = getenv("PORT")
ngrok_tunnel = ngrok.connect(port)
@ngrok_ext.get("/")
async def index(request: Request, user: User = Depends(check_user_exists)):
return ngrok_renderer().TemplateResponse(
"ngrok/index.html", {"request": request, "ngrok": string5, "user": user.dict()} # type: ignore
)