[英]Allowing access to hidden folder from web. Plotly-dash
我認為我的問題可能令人困惑,但我會更好地解釋它。
我想要的是使用 http 請求讓我的應用程序返回位於隱藏目錄中的文件,例如,如果我發出http://mywebsite.com/assets/style.css
請求,我會得到style.css
文件,但是,我也想要讓我的應用程序從隱藏目錄返回文件,例如http://mywebsite.com/.hidden-folder/file
(在這種情況下,我收到200響應但沒有請求文件)
這對我來說是一個新問題,因為我不熟悉web開發,所以我不知道從哪里開始。
我為什么要問這個?
我正在使用certbot
在我的網站中啟用https ,我需要允許從 web 訪問.well-known/acme-challenge/
文件夾,我也很好奇。
這可能會幫助你
目錄結構
├── api
│ ├── app.py
│ ├── __init__.py
├── build
│ ├── .hidden
│ │ └── test.json
#app.py
app = Flask(__name__,static_folder='../build',static_url_path="/")
@app.route('/hidden/<filename>')
def hello_world2(filename):
return app.send_static_file(os.path.join(".hidden", filename))
# or
@app.route('/<path>/<filename>')
def hello_world3(path, filename):
return app.send_static_file(os.path.join(path, filename))
>> curl 127.0.0.1:5000/hidden/test.json
{
"test": "test"
}
>> curl 127.0.0.1:5000/.hidden/test.json
{
"test": "test"
}
這是一個老問題,但我最近遇到了同樣的問題,我使用app.server.route
基本上將在 .well .well-known/acme-challenge
中查找文件的 http01 挑戰重定向到正確的位置 - 在我的例子中是相對路徑到公共文件夾。 這是我在app = dash.Dash(...)
的實例化下方添加到app.py
的代碼。
import flask
# Certificate http01 challenge
@app.server.route("/.well-known/acme-challenge/<path:filename>")
def http01_respond(filename):
return flask.send_file(
"../../public/.well-known/acme-challenge/{}".format(filename)
)
這適用於 Dash 2.7.1。
這與上面的帖子類似,但作為新手,Flask/Dash 的差異對我來說並不明顯!
我在這里寫了一篇關於它的更詳細的文章,但我認為以上內容對於像我一樣被困住的任何人來說已經足夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.