def get_static_files(path): """ getting static files and return content mime types Args: path: path and filename Returns: file content and content type if file found otherwise abort(404) """ static_types = all_mime_types() return Response(get_file(os.path.join(root_dir(), path)), mimetype=static_types.get(os.path.splitext(path)[1], "text/html"))
def get_file(filename): """ open the requested file in HTTP requests Args: filename: path and the filename Returns: content of the file or abort(404) """ try: src = os.path.join(root_dir(), filename) return open(src, 'rb').read() except IOError as _: abort(404)