support a media/ dir under the instance dir
this is for miscellaneous files that should be served directly rather than being a page route
This commit is contained in:
parent
16373d3e55
commit
2634c144a7
@ -3,7 +3,7 @@ import logging
|
||||
import os
|
||||
from logging.config import dictConfig
|
||||
|
||||
from flask import Flask, request
|
||||
from flask import Flask, request, send_from_directory
|
||||
|
||||
from ._version import get_versions
|
||||
|
||||
@ -34,6 +34,11 @@ def create_app(instance_path=None, test_config=None):
|
||||
def log_request():
|
||||
logger.info("REQUEST: [ %s ]", request.path)
|
||||
|
||||
@app.route(f'/{app.config["MEDIA_DIR"]}/<path:filename>')
|
||||
def media_files(filename):
|
||||
return send_from_directory(os.path.join(app.instance_path, app.config['MEDIA_DIR']),
|
||||
filename)
|
||||
|
||||
from . import pages
|
||||
app.register_blueprint(pages.bp)
|
||||
|
||||
|
@ -33,3 +33,4 @@ class Config(object):
|
||||
}
|
||||
|
||||
TITLE_SUFFIX = 'incorporeal.org'
|
||||
MEDIA_DIR = 'media'
|
||||
|
BIN
tests/instance/media/favicon.png
Normal file
BIN
tests/instance/media/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
@ -21,3 +21,9 @@ def test_title_override():
|
||||
response = client.get('/no-title')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>suou.net</title>' in response.data
|
||||
|
||||
|
||||
def test_media_file_access(client):
|
||||
response = client.get('/media/favicon.png')
|
||||
assert response.status_code == 200
|
||||
assert response.headers['content-type'] == 'image/png'
|
||||
|
Loading…
Reference in New Issue
Block a user