Skip to content

Commit bedc5ce

Browse files
committed
add dynamic url
1 parent 2ae7483 commit bedc5ce

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

app.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,47 @@ async def home(request: Request):
6161
})
6262

6363

64+
@app.get("/{path:path}", response_class=HTMLResponse)
65+
async def dynamic_github_route(request: Request, path: str):
66+
"""Handle GitHub-style URLs by replacing gitcontainer.com with github.com."""
67+
# Skip certain paths that shouldn't be treated as GitHub routes
68+
skip_paths = {"health", "favicon.ico", "favicon-16x16.png", "favicon-32x32.png", "apple-touch-icon.png", "static", "ws"}
69+
70+
# Split path into segments
71+
segments = [segment for segment in path.split('/') if segment]
72+
73+
# If it's a skip path, let it fall through
74+
if segments and segments[0] in skip_paths:
75+
from fastapi import HTTPException
76+
raise HTTPException(status_code=404, detail="Not found")
77+
78+
# Check if we have at least 2 segments (username/repo)
79+
if len(segments) < 2:
80+
return templates.TemplateResponse("index.jinja", {
81+
"request": request,
82+
"repo_url": "",
83+
"loading": False,
84+
"streaming": False,
85+
"result": None,
86+
"error": f"Invalid GitHub URL format. Expected format: gitcontainer.com/username/repository",
87+
"pre_filled": False
88+
})
89+
90+
# Use only the first two segments (username/repo)
91+
username, repo = segments[0], segments[1]
92+
github_url = f"https://github.com/{username}/{repo}"
93+
94+
return templates.TemplateResponse("index.jinja", {
95+
"request": request,
96+
"repo_url": github_url,
97+
"loading": False,
98+
"streaming": False,
99+
"result": None,
100+
"error": None,
101+
"pre_filled": True
102+
})
103+
104+
64105
@app.post("/", response_class=HTMLResponse)
65106
async def generate_dockerfile(
66107
request: Request,

templates/index.jinja

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@
106106
</div>
107107
{% endif %}
108108

109+
<!-- Pre-filled URL notification -->
110+
{% if pre_filled %}
111+
<div class="mb-6 p-4 bg-green-50 border-[3px] border-green-500 rounded-lg text-green-700">
112+
<div class="flex items-center gap-2">
113+
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
114+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
115+
</svg>
116+
<span class="font-medium">Great! We've automatically detected your GitHub repository from the URL.</span>
117+
</div>
118+
<p class="text-sm mt-1">You can now generate a Dockerfile for this repository, or modify the URL if needed.</p>
119+
</div>
120+
{% endif %}
121+
109122
<!-- Input Form -->
110123
<div class="relative mb-8">
111124
<div class="w-full h-full absolute inset-0 bg-gray-900 rounded-xl translate-y-2 translate-x-2"></div>

0 commit comments

Comments
 (0)