diff --git a/docs/configuration.rst b/docs/configuration.rst index 7502cef40..99721b976 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -154,10 +154,6 @@ PAPERLESS_FORCE_SCRIPT_NAME= To host paperless under a subpath url like example.com/paperless you set this value to /paperless. No trailing slash! - .. note:: - - I don't know if this works in paperless-ng. Probably not. - Defaults to none, which hosts paperless at "/". PAPERLESS_STATIC_URL= diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 995b4fb9d..bcc12490e 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -2,7 +2,7 @@ import os bind = '0.0.0.0:8000' workers = int(os.getenv("PAPERLESS_WEBSERVER_WORKERS", 2)) -worker_class = 'uvicorn.workers.UvicornWorker' +worker_class = 'paperless.workers.ConfigurableWorker' timeout = 120 def pre_fork(server, worker): diff --git a/src-ui/src/app/app.component.ts b/src-ui/src/app/app.component.ts index 836a6f66a..2b828d3b0 100644 --- a/src-ui/src/app/app.component.ts +++ b/src-ui/src/app/app.component.ts @@ -18,7 +18,7 @@ export class AppComponent implements OnInit, OnDestroy { constructor (private settings: SettingsService, private consumerStatusService: ConsumerStatusService, private toastService: ToastService, private router: Router) { let anyWindow = (window as any) - anyWindow.pdfWorkerSrc = '/assets/js/pdf.worker.min.js'; + anyWindow.pdfWorkerSrc = 'assets/js/pdf.worker.min.js'; this.settings.updateDarkModeSettings() } diff --git a/src-ui/src/app/services/consumer-status.service.ts b/src-ui/src/app/services/consumer-status.service.ts index e03282175..4a729b29d 100644 --- a/src-ui/src/app/services/consumer-status.service.ts +++ b/src-ui/src/app/services/consumer-status.service.ts @@ -125,7 +125,7 @@ export class ConsumerStatusService { connect() { this.disconnect() - this.statusWebSocket = new WebSocket(`${environment.webSocketProtocol}//${environment.webSocketHost}/ws/status/`); + this.statusWebSocket = new WebSocket(`${environment.webSocketProtocol}//${environment.webSocketHost}${environment.webSocketBaseUrl}status/`); this.statusWebSocket.onmessage = (ev) => { let statusMessage: WebsocketConsumerStatusMessage = JSON.parse(ev['data']) diff --git a/src-ui/src/environments/environment.prod.ts b/src-ui/src/environments/environment.prod.ts index b60824248..54c32d370 100644 --- a/src-ui/src/environments/environment.prod.ts +++ b/src-ui/src/environments/environment.prod.ts @@ -1,9 +1,12 @@ +const base_url = new URL(document.baseURI) + export const environment = { production: true, - apiBaseUrl: "/api/", + apiBaseUrl: document.baseURI + "api/", apiVersion: "2", appTitle: "Paperless-ng", version: "1.4.2", webSocketHost: window.location.host, - webSocketProtocol: (window.location.protocol == "https:" ? "wss:" : "ws:") + webSocketProtocol: (window.location.protocol == "https:" ? "wss:" : "ws:"), + webSocketBaseUrl: base_url.pathname + "ws/", }; diff --git a/src-ui/src/environments/environment.ts b/src-ui/src/environments/environment.ts index 3d981b677..3b8a02e37 100644 --- a/src-ui/src/environments/environment.ts +++ b/src-ui/src/environments/environment.ts @@ -9,7 +9,8 @@ export const environment = { appTitle: "Paperless-ng", version: "DEVELOPMENT", webSocketHost: "localhost:8000", - webSocketProtocol: "ws:" + webSocketProtocol: "ws:", + webSocketBaseUrl: "/ws/", }; /* diff --git a/src/documents/templates/index.html b/src/documents/templates/index.html index c4beea07a..b8f60a9a5 100644 --- a/src/documents/templates/index.html +++ b/src/documents/templates/index.html @@ -7,7 +7,7 @@ Paperless-ng - + diff --git a/src/documents/templates/registration/logged_out.html b/src/documents/templates/registration/logged_out.html index e4571483d..b6438a34a 100644 --- a/src/documents/templates/registration/logged_out.html +++ b/src/documents/templates/registration/logged_out.html @@ -43,7 +43,7 @@

{% translate "You have been successfully logged out. Bye!" %}

- {% translate "Sign in again" %} + {% translate "Sign in again" %} diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 26a4d5621..39504fe54 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -142,11 +142,14 @@ MIDDLEWARE = [ ROOT_URLCONF = 'paperless.urls' FORCE_SCRIPT_NAME = os.getenv("PAPERLESS_FORCE_SCRIPT_NAME") +BASE_URL = (FORCE_SCRIPT_NAME or "") + "/" +LOGIN_URL = BASE_URL + "accounts/login/" WSGI_APPLICATION = 'paperless.wsgi.application' ASGI_APPLICATION = "paperless.asgi.application" -STATIC_URL = os.getenv("PAPERLESS_STATIC_URL", "/static/") +STATIC_URL = os.getenv("PAPERLESS_STATIC_URL", BASE_URL + "static/") +WHITENOISE_STATIC_PREFIX = "/static/" # TODO: what is this used for? TEMPLATES = [ diff --git a/src/paperless/urls.py b/src/paperless/urls.py index 7521d49de..eee04af9f 100755 --- a/src/paperless/urls.py +++ b/src/paperless/urls.py @@ -9,6 +9,8 @@ from rest_framework.routers import DefaultRouter from django.utils.translation import gettext_lazy as _ +from django.conf import settings + from paperless.consumers import StatusConsumer from documents.views import ( CorrespondentViewSet, @@ -73,31 +75,36 @@ urlpatterns = [ re_path(r"^fetch/", include([ re_path( r"^doc/(?P\d+)$", - RedirectView.as_view(url='/api/documents/%(pk)s/download/'), + RedirectView.as_view(url=settings.BASE_URL + + 'api/documents/%(pk)s/download/'), ), re_path( r"^thumb/(?P\d+)$", - RedirectView.as_view(url='/api/documents/%(pk)s/thumb/'), + RedirectView.as_view(url=settings.BASE_URL + + 'api/documents/%(pk)s/thumb/'), ), re_path( r"^preview/(?P\d+)$", - RedirectView.as_view(url='/api/documents/%(pk)s/preview/'), + RedirectView.as_view(url=settings.BASE_URL + + 'api/documents/%(pk)s/preview/'), ), ])), re_path(r"^push$", csrf_exempt( - RedirectView.as_view(url='/api/documents/post_document/'))), + RedirectView.as_view(url=settings.BASE_URL + + 'api/documents/post_document/'))), # Frontend assets TODO: this is pretty bad, but it works. path('assets/', - RedirectView.as_view(url='/static/frontend/en-US/assets/%(path)s')), + RedirectView.as_view(url=settings.STATIC_URL + + 'frontend/en-US/assets/%(path)s')), # TODO: with localization, this is even worse! :/ # login, logout path('accounts/', include('django.contrib.auth.urls')), # Root of the Frontent - re_path(r".*", login_required(IndexView.as_view())), + re_path(r".*", login_required(IndexView.as_view()), name='base'), ] diff --git a/src/paperless/workers.py b/src/paperless/workers.py new file mode 100644 index 000000000..4f2f0802a --- /dev/null +++ b/src/paperless/workers.py @@ -0,0 +1,11 @@ +import os +from uvicorn.workers import UvicornWorker +from django.conf import settings + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings") + + +class ConfigurableWorker(UvicornWorker): + CONFIG_KWARGS = { + "root_path": settings.FORCE_SCRIPT_NAME or "", + }