Spaces:
Running
Running
Commit
·
5bea760
1
Parent(s):
09acca8
Use https for all the static assets
Browse files- app/main.py +13 -0
- app/templates/base.html +1 -1
- app/templates/index.html +1 -1
- app/templates/video.html +1 -1
app/main.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.staticfiles import StaticFiles
|
| 3 |
from fastapi.templating import Jinja2Templates
|
|
@@ -5,6 +7,8 @@ from fastapi.responses import HTMLResponse, RedirectResponse
|
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from app.api import router as api_router
|
| 7 |
from app.services.video_service import get_video_by_id
|
|
|
|
|
|
|
| 8 |
|
| 9 |
app = FastAPI(title="In-Video Search", docs_url=None, redoc_url=None, openapi_url=None)
|
| 10 |
|
|
@@ -24,6 +28,15 @@ app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|
| 24 |
templates = Jinja2Templates(directory="app/templates")
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
@app.get("/", response_class=HTMLResponse)
|
| 28 |
async def index(request: Request):
|
| 29 |
return templates.TemplateResponse(
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from fastapi.templating import Jinja2Templates
|
|
|
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
from app.api import router as api_router
|
| 9 |
from app.services.video_service import get_video_by_id
|
| 10 |
+
from jinja2 import pass_context
|
| 11 |
+
from starlette.datastructures import URL
|
| 12 |
|
| 13 |
app = FastAPI(title="In-Video Search", docs_url=None, redoc_url=None, openapi_url=None)
|
| 14 |
|
|
|
|
| 28 |
templates = Jinja2Templates(directory="app/templates")
|
| 29 |
|
| 30 |
|
| 31 |
+
@pass_context
|
| 32 |
+
def https_url_for(context: dict, name: str, **path_params: Any) -> URL:
|
| 33 |
+
request: Request = context["request"]
|
| 34 |
+
url: URL = request.url_for(name, **path_params)
|
| 35 |
+
return url.replace(scheme="https")
|
| 36 |
+
|
| 37 |
+
templates.env.globals["https_url_for"] = https_url_for
|
| 38 |
+
|
| 39 |
+
|
| 40 |
@app.get("/", response_class=HTMLResponse)
|
| 41 |
async def index(request: Request):
|
| 42 |
return templates.TemplateResponse(
|
app/templates/base.html
CHANGED
|
@@ -76,7 +76,7 @@
|
|
| 76 |
</footer>
|
| 77 |
|
| 78 |
<!-- Scripts -->
|
| 79 |
-
<script src="{{
|
| 80 |
{% block scripts %}{% endblock %}
|
| 81 |
</body>
|
| 82 |
</html>
|
|
|
|
| 76 |
</footer>
|
| 77 |
|
| 78 |
<!-- Scripts -->
|
| 79 |
+
<script src="{{ https_url_for('static', path='/js/main.js') }}"></script>
|
| 80 |
{% block scripts %}{% endblock %}
|
| 81 |
</body>
|
| 82 |
</html>
|
app/templates/index.html
CHANGED
|
@@ -94,5 +94,5 @@
|
|
| 94 |
{% endblock %}
|
| 95 |
|
| 96 |
{% block scripts %}
|
| 97 |
-
<script src="{{
|
| 98 |
{% endblock %}
|
|
|
|
| 94 |
{% endblock %}
|
| 95 |
|
| 96 |
{% block scripts %}
|
| 97 |
+
<script src="{{ https_url_for('static', path='/js/index.js') }}"></script>
|
| 98 |
{% endblock %}
|
app/templates/video.html
CHANGED
|
@@ -58,5 +58,5 @@
|
|
| 58 |
// Store the video ID in a JavaScript variable
|
| 59 |
const videoId = "{{ video_id }}";
|
| 60 |
</script>
|
| 61 |
-
<script src="{{
|
| 62 |
{% endblock %}
|
|
|
|
| 58 |
// Store the video ID in a JavaScript variable
|
| 59 |
const videoId = "{{ video_id }}";
|
| 60 |
</script>
|
| 61 |
+
<script src="{{ https_url_for('static', path='/js/video.js') }}"></script>
|
| 62 |
{% endblock %}
|