Created
December 10, 2023 20:14
-
-
Save epoz/06fdd0705d395b963ab181a61221c206 to your computer and use it in GitHub Desktop.
Falcon script to server contents of multiple directories on single root path over HTTP for X-Accel-Redirect headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import falcon | |
import falcon.asgi | |
import os | |
async def diefolt(req, resp, **kwargs): | |
_, filename = os.path.split(req.path) | |
resp.status = falcon.HTTP_404 | |
resp.text = f'{filename} Not Found' | |
SOURCES = ['/data/ap/beeldbank_images/', '/data/blm/images/'] | |
for s in SOURCES: | |
filepath = os.path.join(s, filename) | |
if os.path.exists(filepath): | |
resp.set_header('X-Accel-Redirect', filepath.replace('/data', '')) | |
resp.status = falcon.HTTP_200 | |
resp.text = 'Found' | |
app = falcon.asgi.App() | |
app.add_sink(diefolt, '/') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment