server: docker setup for embeds, sharing client's /var/www to the server

This commit is contained in:
ItsKaa
2024-11-11 19:28:06 +01:00
committed by Eva
parent e59beb4670
commit d03c4c7b5e
3 changed files with 25 additions and 2 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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:
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<path>/.+)")
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: