mirror of
https://github.com/clearml/clearml-server
synced 2025-06-23 08:45:30 +00:00
Add File server CORS support
This commit is contained in:
parent
02671910b2
commit
bed714890d
8
fileserver/config/default/fileserver.conf
Normal file
8
fileserver/config/default/fileserver.conf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
download {
|
||||||
|
# Add response headers requesting no caching for served files
|
||||||
|
disable_browser_caching: false
|
||||||
|
}
|
||||||
|
|
||||||
|
cors {
|
||||||
|
origins: "*"
|
||||||
|
}
|
@ -1,16 +1,18 @@
|
|||||||
""" A Simple file server for uploading and downloading files """
|
""" A Simple file server for uploading and downloading files """
|
||||||
import json
|
import json
|
||||||
import logging.config
|
|
||||||
import os
|
import os
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from flask import Flask, request, send_from_directory, safe_join
|
from flask import Flask, request, send_from_directory, safe_join
|
||||||
from pyhocon import ConfigFactory
|
from flask_compress import Compress
|
||||||
|
from flask_cors import CORS
|
||||||
|
|
||||||
logging.config.dictConfig(ConfigFactory.parse_file("logging.conf"))
|
from config import config
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
CORS(app, **config.get("fileserver.cors"))
|
||||||
|
Compress(app)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/", methods=["POST"])
|
@app.route("/", methods=["POST"])
|
||||||
@ -29,7 +31,15 @@ def upload():
|
|||||||
|
|
||||||
@app.route("/<path:path>", methods=["GET"])
|
@app.route("/<path:path>", methods=["GET"])
|
||||||
def download(path):
|
def download(path):
|
||||||
return send_from_directory(app.config["UPLOAD_FOLDER"], path)
|
response = send_from_directory(app.config["UPLOAD_FOLDER"], path)
|
||||||
|
if config.get("fileserver.download.disable_browser_caching", False):
|
||||||
|
headers = response.headers
|
||||||
|
headers["Pragma-directive"] = "no-cache"
|
||||||
|
headers["Cache-directive"] = "no-cache"
|
||||||
|
headers["Cache-control"] = "no-cache"
|
||||||
|
headers["Pragma"] = "no-cache"
|
||||||
|
headers["Expires"] = "0"
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
Flask
|
Flask
|
||||||
|
Flask-Cors>=3.0.5
|
||||||
|
Flask-Compress>=1.4.0
|
||||||
pyhocon>=0.3.35
|
pyhocon>=0.3.35
|
Loading…
Reference in New Issue
Block a user