6
0
Просмотр исходного кода

Merge branch '29-svg-files-need-the-correct-mime-type-to-be-displayed-correctly' into 'master'

Resolve "svg files need the correct mime type to be displayed correctly"

Closes #29

See merge request troebs/pycs!25
Eric Tröbs 4 лет назад
Родитель
Сommit
bbe7df8b19
1 измененных файлов с 10 добавлено и 7 удалено
  1. 10 7
      pycs/frontend/WebServer.py

+ 10 - 7
pycs/frontend/WebServer.py

@@ -1,3 +1,4 @@
+from glob import glob
 from os.path import exists
 
 import eventlet
@@ -10,17 +11,19 @@ from pycs.frontend.FileProvider import FileProvider
 class WebServer:
     def __init__(self, app_status: ApplicationStatus):
         # initialize web server
-        # TODO svg files need the correct mime type to be displayed correctly
         if exists('webui/index.html'):
             print('production build')
             files = FileProvider(app_status)
+
+            # find svg icons and add them as separate static files to
+            # set their correct mime type / content_type
+            static_files = {'/': 'webui/'}
+            for path in glob('webui/img/*.svg'):
+                path = path.replace('\\', '/')
+                static_files[path[5:]] = {'content_type': 'image/svg+xml', 'filename': path}
+
             self.__sio = socketio.Server()
-            self.__app = socketio.WSGIApp(self.__sio, files, static_files={'/': 'webui/'})
-        elif exists('webui/dist/index.html'):
-            print('production build')
-            files = FileProvider(app_status)
-            self.__sio = socketio.Server()
-            self.__app = socketio.WSGIApp(self.__sio, files, static_files={'/': 'webui/dist/'})
+            self.__app = socketio.WSGIApp(self.__sio, files, static_files=static_files)
         else:
             print('development build')
             files = FileProvider(app_status, cors=True)