Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SayesCode authored Nov 7, 2024
1 parent 67ad2dd commit 390c63d
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/onyconnect/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
import os
from tor_config import generate_onion_service
import uvicorn
import logging
import uvicorn
from tor_config import generate_onion_service

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
app = FastAPI()

# Defining the path for 'static' and 'templates' directories
# Defining paths for static and templates directories
static_path = os.path.join(os.path.dirname(__file__), 'static')
templates_path = os.path.join(os.path.dirname(__file__), 'templates')

# Defining the templates folder
templates = Jinja2Templates(directory=templates_path)

# Mounting the 'static' folder to serve static files
app.mount("/static", StaticFiles(directory=static_path), name="static")

@app.get("/", response_class=HTMLResponse)
Expand All @@ -26,19 +23,16 @@ async def index(request: Request):

@app.post("/generate")
async def generate_service(request: Request, port: str = Form(...)):
# Generating the Onion service using the function defined in tor_config
hostname = generate_onion_service(port)

# Defining the message based on the result of generating the Onion service
if hostname:
message = f"Onion service created successfully: {hostname}"
else:
message = "Failed to create the Onion service. Please check the configurations."

# Returning the response with the message to the page

return templates.TemplateResponse("index.html", {"request": request, "message": message})

logging.info('Open: http://localhost:8000')
logging.info('Server is running at http://localhost:8000')

if __name__ == "__main__":
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)

0 comments on commit 390c63d

Please sign in to comment.