Browse Source

serve frontend files

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

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

@@ -1,5 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2
+import os
2 3
 
4
+from tracim_backend.views.frontend import FrontendController
3 5
 
4 6
 try:  # Python 3.5+
5 7
     from http import HTTPStatus
@@ -106,6 +108,7 @@ def web(global_config, **local_settings):
106 108
     context.handle_exception(OperationalError, HTTPStatus.INTERNAL_SERVER_ERROR)
107 109
     context.handle_exception(Exception, HTTPStatus.INTERNAL_SERVER_ERROR)
108 110
 
111
+
109 112
     # Add controllers
110 113
     session_controller = SessionController()
111 114
     system_controller = SystemController()
@@ -124,6 +127,10 @@ def web(global_config, **local_settings):
124 127
     configurator.include(thread_controller.bind, route_prefix=BASE_API_V2)
125 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 134
     hapic.add_documentation_view(
128 135
         '/api/v2/doc',
129 136
         'Tracim v2 API',

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

@@ -1,5 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from urllib.parse import urlparse
3
+
4
+import os
3 5
 from paste.deploy.converters import asbool
4 6
 from tracim_backend.lib.utils.logger import logger
5 7
 from depot.manager import DepotManager
@@ -435,6 +437,29 @@ class CFG(object):
435 437
 
436 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 463
     def configure_filedepot(self):
439 464
         depot_storage_name = self.DEPOT_STORAGE_NAME
440 465
         depot_storage_path = self.DEPOT_STORAGE_DIR

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

@@ -39,7 +39,6 @@ from tracim_backend.models.contents import CONTENT_TYPES
39 39
 SWAGGER_TAG__USER_ENDPOINTS = 'Users'
40 40
 
41 41
 
42
-
43 42
 class UserController(Controller):
44 43
 
45 44
     @hapic.with_api_doc(tags=[SWAGGER_TAG__USER_ENDPOINTS])