Browse Source

serve frontend files

Guénaël Muller 6 years ago
parent
commit
8f057c6e31

+ 7 - 0
backend/tracim_backend/__init__.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
+import os
2
 
3
 
4
+from tracim_backend.views.frontend import FrontendController
3
 
5
 
4
 try:  # Python 3.5+
6
 try:  # Python 3.5+
5
     from http import HTTPStatus
7
     from http import HTTPStatus
106
     context.handle_exception(OperationalError, HTTPStatus.INTERNAL_SERVER_ERROR)
108
     context.handle_exception(OperationalError, HTTPStatus.INTERNAL_SERVER_ERROR)
107
     context.handle_exception(Exception, HTTPStatus.INTERNAL_SERVER_ERROR)
109
     context.handle_exception(Exception, HTTPStatus.INTERNAL_SERVER_ERROR)
108
 
110
 
111
+
109
     # Add controllers
112
     # Add controllers
110
     session_controller = SessionController()
113
     session_controller = SessionController()
111
     system_controller = SystemController()
114
     system_controller = SystemController()
124
     configurator.include(thread_controller.bind, route_prefix=BASE_API_V2)
127
     configurator.include(thread_controller.bind, route_prefix=BASE_API_V2)
125
     configurator.include(file_controller.bind, route_prefix=BASE_API_V2)
128
     configurator.include(file_controller.bind, route_prefix=BASE_API_V2)
126
 
129
 
130
+    if app_config.FRONTEND_SERVE:
131
+        frontend_controller = FrontendController(app_config.FRONTEND_DIST_FOLDER_PATH)  # nopep8
132
+        configurator.include(frontend_controller.bind)
133
+
127
     hapic.add_documentation_view(
134
     hapic.add_documentation_view(
128
         '/api/v2/doc',
135
         '/api/v2/doc',
129
         'Tracim v2 API',
136
         'Tracim v2 API',

+ 25 - 0
backend/tracim_backend/config.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 from urllib.parse import urlparse
2
 from urllib.parse import urlparse
3
+
4
+import os
3
 from paste.deploy.converters import asbool
5
 from paste.deploy.converters import asbool
4
 from tracim_backend.lib.utils.logger import logger
6
 from tracim_backend.lib.utils.logger import logger
5
 from depot.manager import DepotManager
7
 from depot.manager import DepotManager
435
 
437
 
436
         self.PREVIEW_JPG_ALLOWED_DIMS = allowed_dims
438
         self.PREVIEW_JPG_ALLOWED_DIMS = allowed_dims
437
 
439
 
440
+        self.FRONTEND_SERVE = asbool(settings.get(
441
+            'frontend.serve', False
442
+        ))
443
+
444
+        # INFO - G.M - 2018-08-06 - we pretend that frontend_dist_folder
445
+        # is probably in frontend subfolder
446
+        # of tracim_v2 parent of both backend and frontend
447
+        backend_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  # nopep8
448
+        tracim_v2_folder = os.path.dirname(backend_folder)
449
+        frontend_dist_folder = os.path.join(tracim_v2_folder, 'frontend', 'dist')  # nopep8
450
+
451
+        self.FRONTEND_DIST_FOLDER_PATH = settings.get(
452
+            'frontend.dist_folder_path', frontend_dist_folder
453
+        )
454
+
455
+        # INFO - G.M - 2018-08-06 - We check dist folder existence
456
+        if self.FRONTEND_SERVE and not os.path.isdir(self.FRONTEND_DIST_FOLDER_PATH):  # nopep8
457
+            raise Exception(
458
+                'ERROR: {} folder does not exist as folder. '
459
+                'please set frontend.dist_folder.path'
460
+                'with a correct value'.format(self.FRONTEND_DIST_FOLDER_PATH)
461
+            )
462
+
438
     def configure_filedepot(self):
463
     def configure_filedepot(self):
439
         depot_storage_name = self.DEPOT_STORAGE_NAME
464
         depot_storage_name = self.DEPOT_STORAGE_NAME
440
         depot_storage_path = self.DEPOT_STORAGE_DIR
465
         depot_storage_path = self.DEPOT_STORAGE_DIR

+ 0 - 1
backend/tracim_backend/views/core_api/user_controller.py View File

39
 SWAGGER_TAG__USER_ENDPOINTS = 'Users'
39
 SWAGGER_TAG__USER_ENDPOINTS = 'Users'
40
 
40
 
41
 
41
 
42
-
43
 class UserController(Controller):
42
 class UserController(Controller):
44
 
43
 
45
     @hapic.with_api_doc(tags=[SWAGGER_TAG__USER_ENDPOINTS])
44
     @hapic.with_api_doc(tags=[SWAGGER_TAG__USER_ENDPOINTS])