Skip to content

Instantly share code, notes, and snippets.

@mgoldey
Created November 11, 2019 21:23
Show Gist options
  • Save mgoldey/6e62f9c17dfa98fee7bf0e91e5d70d7c to your computer and use it in GitHub Desktop.
Save mgoldey/6e62f9c17dfa98fee7bf0e91e5d70d7c to your computer and use it in GitHub Desktop.
a small file serving falcon app
import os
import falcon
import mimetypes
class Files:
def on_get(self, req, resp, name=""):
"""Handles GET requests"""
PWD=os.path.abspath("./")
file_loc = os.sep.join([PWD,name])
if os.path.isfile(file_loc):
with open(file_loc, 'rb') as data:
resp.status = falcon.HTTP_200
resp.content_type = mimetypes.guess_type(file_loc)
resp.body = data.read()
api = falcon.API()
api.add_route("/files/{name}", Files())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment