fontra icon indicating copy to clipboard operation
fontra copied to clipboard

[idea] Add an option to host the service under subdirectory

Open NightFurySL2001 opened this issue 9 months ago • 1 comments

It would be good to allow fontra to be started under a subdirectory path. Currently Fontra starts at the service root and most things are loaded with absolute path (e.g. /css/, /assets/), however it would be desirable to host it under subdirectory such that, e.g. permission control can be done with nginx by hosting Fontra on different sudirectory (https://internal.dev/project1 and https://internal.dev/project2) and configuring permission control to them.

I have tried to do this with nginx by proxying and rewriting the file path with the following config in Docker: nginx.conf however the websocket is broken with the subdirectory:

2024-05-07 21:41:40 fontra-fontra-1  | 2024-05-07 13:41:40 fontra.core.server INFO     incoming connection from 172.22.0.1 for '/-/src-heavy.ufo'
2024-05-07 21:41:40 fontra-fontra-1  | 2024-05-07 13:41:40 fontra.core.server ERROR    error while handling incoming websocket messages: FileNotFoundError(None)
2024-05-07 21:41:40 fontra-fontra-1  | Traceback (most recent call last):
2024-05-07 21:41:40 fontra-fontra-1  |   File "/fontra/src/fontra/core/server.py", line 160, in websocketHandler
2024-05-07 21:41:40 fontra-fontra-1  |     subject = await self.getSubject(websocket, path, token)
2024-05-07 21:41:40 fontra-fontra-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-07 21:41:40 fontra-fontra-1  |   File "/fontra/src/fontra/core/server.py", line 180, in getSubject
2024-05-07 21:41:40 fontra-fontra-1  |     subject = await self.projectManager.getRemoteSubject(path, token)
2024-05-07 21:41:40 fontra-fontra-1  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-07 21:41:40 fontra-fontra-1  |   File "/fontra/src/fontra/filesystem/projectmanager.py", line 101, in getRemoteSubject
2024-05-07 21:41:40 fontra-fontra-1  |     raise FileNotFoundError(projectPath)
2024-05-07 21:41:40 fontra-fontra-1  | FileNotFoundError: None
2024-05-07 21:41:40 fontra-nginx-1   | 172.22.0.1 - - [07/May/2024:13:41:40 +0000] "GET /fontra/websocket/-/src-heavy.ufo HTTP/1.1" 101 4 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "-"
2024-05-07 21:41:40 fontra-fontra-1  | 2024-05-07 13:41:40 aiohttp.access    INFO     172.22.0.3 [07/May/2024:13:41:40 +0000] "GET /websocket/-/src-heavy.ufo HTTP/1.1" 101 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"

NightFurySL2001 avatar May 10 '24 11:05 NightFurySL2001

On the one hand, I think this is a desirable feature, but I am not sure that using separate Fontra instances for separate projects is the the ultimate solution, especially since it would mean that assets would not be shared among instances.

In fontra-rcjk we use a database backend which also manages authentication. (I don't recommend this implementation at this point, it is mostly a legacy project, and we're in the process of replacing it.)

justvanrossum avatar May 16 '24 07:05 justvanrossum