Skip to content

Instantly share code, notes, and snippets.

@epoz
Created December 10, 2023 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epoz/06fdd0705d395b963ab181a61221c206 to your computer and use it in GitHub Desktop.
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
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