Include an error message if we can't find an external document.

master
Pacman Ghost 4 years ago
parent 97e3cd1812
commit 237b6ff7d7
  1. 1
      asl_articles/__init__.py
  2. 9
      asl_articles/docs.py
  3. 1
      docker-compose.yml

@ -85,6 +85,7 @@ app.config.update( _cfg )
# connect to the database
# NOTE: We assume that this web server will only be handling a single user. If we ever have
# multiple concurrent users, we will need to change to per-session database connections.
app.config[ "_IS_CONTAINER" ] = _cfg.get( "IS_CONTAINER" )
if _cfg.get( "IS_CONTAINER" ):
# if we are running in a container, the database must be specified in an env variable e.g.
# docker run -e DBCONN=...

@ -1,5 +1,7 @@
""" Provide access to external documents. """
import os
from flask import abort, send_from_directory
from asl_articles import app
@ -11,5 +13,10 @@ def get_external_doc( path ):
"""Return an external document."""
base_dir = app.config.get( "EXTERNAL_DOCS_BASEDIR" )
if not base_dir:
abort( 404 )
abort( 404, "EXTERNAL_DOCS_BASEDIR not configured." )
fname = os.path.join( base_dir, path )
if not os.path.isfile( fname ):
if app.config["_IS_CONTAINER"]:
fname = os.path.join( os.environ["EXTERNAL_DOCS_BASEDIR"], path )
abort( 404, "Can't find file: {}".format( fname ) )
return send_from_directory( base_dir, path )

@ -35,3 +35,4 @@ services:
- $EXTERNAL_DOCS_BASEDIR:/data/docs/
environment:
- DBCONN
- EXTERNAL_DOCS_BASEDIR

Loading…
Cancel
Save