Created
November 11, 2019 21:23
-
-
Save mgoldey/6e62f9c17dfa98fee7bf0e91e5d70d7c to your computer and use it in GitHub Desktop.
a small file serving falcon app
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 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