@@ -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 )
65106async def generate_dockerfile (
66107 request : Request ,
0 commit comments