Abhinav633 commited on
Commit
15db74a
·
verified ·
1 Parent(s): a791484

Create patch.py

Browse files
Files changed (1) hide show
  1. patch.py +33 -0
patch.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ patch = '''
4
+ from fastapi.staticfiles import StaticFiles
5
+ from fastapi.responses import FileResponse
6
+ import os as _os
7
+
8
+ _static_dir = _os.path.join(_os.path.dirname(__file__), 'static')
9
+ if _os.path.exists(_static_dir):
10
+ app.mount('/assets', StaticFiles(directory=_os.path.join(_static_dir,'assets')), name='assets')
11
+
12
+ @app.get('/{full_path:path}')
13
+ async def serve_spa(full_path: str):
14
+ index = _os.path.join(_static_dir, 'index.html')
15
+ return FileResponse(index)
16
+ '''
17
+
18
+ content = open('backend/main.py').read()
19
+ insert_after = 'allow_headers=["*"],\n)'
20
+ content = content.replace(insert_after, insert_after + '\n' + patch)
21
+ open('backend/main.py', 'w').write(content)
22
+ print("patch.py applied successfully")
23
+ ```
24
+
25
+ ---
26
+
27
+ So your root files should now look like:
28
+ ```
29
+ Dockerfile ← replaced
30
+ patch.py ← new file
31
+ backend/
32
+ frontend/
33
+ README.md