diff --git a/docker-compose.yml b/docker-compose.yml index 38e08b97..3570d8a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,8 +23,12 @@ services: #LOG_SQL: 0 (1 for verbose SQL logs) THREADS: volumes: + - client:/opt/app/client:ro - "${MOUNT_DATA}:/data" - "./server/config.yaml:/opt/app/config.yaml" + ## Expose this port if you want embeds + #ports: + # - "${PORT_SERVER}:6666" client: image: szurubooru/client:latest @@ -34,6 +38,7 @@ services: BACKEND_HOST: server BASE_URL: volumes: + - client:/var/www - "${MOUNT_DATA}:/data:ro" ports: - "${PORT}:80" @@ -46,3 +51,6 @@ services: POSTGRES_PASSWORD: volumes: - "${MOUNT_SQL}:/var/lib/postgresql/data" + +volumes: + client: diff --git a/server/config.yaml.dist b/server/config.yaml.dist index 222ec06a..6c992965 100644 --- a/server/config.yaml.dist +++ b/server/config.yaml.dist @@ -172,11 +172,16 @@ privileges: homepage_url: https://www.example.com/ site_url: https://www.example.com/booru +## Client folder sharing, required for embeds. +# Docker requires you to share /var/www from the client to the server. +client_dir: /opt/app/client + ## ONLY SET THESE IF DEPLOYING OUTSIDE OF DOCKER #debug: 0 # generate server logs? #show_sql: 0 # show sql in server logs? #data_url: /data/ #data_dir: /var/www/data +#client_dir: /var/www ## usage: schema://user:password@host:port/database_name ## example: postgres://szuru:dog@localhost:5432/szuru_test #database: diff --git a/server/szurubooru/api/embed_api.py b/server/szurubooru/api/embed_api.py index d2a7b577..6ee12fb4 100644 --- a/server/szurubooru/api/embed_api.py +++ b/server/szurubooru/api/embed_api.py @@ -1,3 +1,5 @@ +import logging +from pathlib import Path import re import html from urllib.parse import quote @@ -10,8 +12,11 @@ from szurubooru.func import ( serialization, ) -with open(f"{config.config['data_dir']}/../index.htm") as index: - index_html = index.read() +if (Path(config.config['client_dir']) / "index.htm").exists(): + with open(f"{config.config['client_dir']}/index.htm") as index: + index_html = index.read() +else: + logging.warning("Could not find index.htm needed for embeds.") def _index_path(params: Dict[str, str]) -> int: try: @@ -78,6 +83,11 @@ def get_post( @rest.routes.get("/index(?P/.+)") def post_index(ctx: rest.Context, params: Dict[str, str]) -> rest.Response: path = _index_path(params) + + if not index_html: + logging.info("Embed was requested but index.htm file does not exist. Redirecting to 404.") + return {"return_type": "custom", "status_code": "404", "content": [("content-type", "text/html")]} + try: oembed = get_post(ctx, {}, path) except posts.PostNotFoundError: