|
@@ -1,13 +1,13 @@
|
1
|
1
|
import os
|
2
|
2
|
|
3
|
|
-from pyramid.response import Response
|
|
3
|
+from pyramid.renderers import render_to_response
|
4
|
4
|
from pyramid.config import Configurator
|
5
|
5
|
from tracim_backend.exceptions import PageNotFound
|
6
|
6
|
from tracim_backend.views import BASE_API_V2
|
7
|
7
|
from tracim_backend.lib.utils.request import TracimRequest
|
8
|
8
|
from tracim_backend.views.controllers import Controller
|
9
|
9
|
|
10
|
|
-INDEX_PAGE_NAME = 'index.html'
|
|
10
|
+INDEX_PAGE_NAME = 'index.mak'
|
11
|
11
|
|
12
|
12
|
|
13
|
13
|
class FrontendController(Controller):
|
|
@@ -15,21 +15,23 @@ class FrontendController(Controller):
|
15
|
15
|
def __init__(self, dist_folder_path: str):
|
16
|
16
|
self.dist_folder_path = dist_folder_path
|
17
|
17
|
|
|
18
|
+ def _get_index_file_path(self):
|
|
19
|
+ index_file_path = os.path.join(self.dist_folder_path, INDEX_PAGE_NAME)
|
|
20
|
+ if not os.path.exists(index_file_path):
|
|
21
|
+ raise FileNotFoundError()
|
|
22
|
+ return index_file_path
|
|
23
|
+
|
18
|
24
|
def not_found_view(self, context, request: TracimRequest):
|
19
|
25
|
|
20
|
26
|
if request.path.startswith(BASE_API_V2):
|
21
|
|
- raise PageNotFound('{} is not a valid path'.format(request.path)) from context
|
|
27
|
+ raise PageNotFound('{} is not a valid path'.format(request.path)) from context # nopep8
|
22
|
28
|
return self.index(context, request)
|
23
|
29
|
|
24
|
30
|
def index(self, context, request: TracimRequest):
|
25
|
|
- index_file_path = os.path.join(self.dist_folder_path, INDEX_PAGE_NAME)
|
26
|
|
- if not os.path.exists(index_file_path):
|
27
|
|
- raise FileNotFoundError()
|
28
|
|
- with open(index_file_path) as file:
|
29
|
|
- return Response(
|
30
|
|
- content_type='text/html',
|
31
|
|
- body=file.read()
|
32
|
|
- )
|
|
31
|
+ return render_to_response(
|
|
32
|
+ self._get_index_file_path(),
|
|
33
|
+ {}
|
|
34
|
+ )
|
33
|
35
|
|
34
|
36
|
def bind(self, configurator: Configurator) -> None:
|
35
|
37
|
|