Allowing access to hidden folder from web. Plotly-dash
Question:
I think my question can be confusing, but I’ll explain it better.
What I want is to have my app return files located in hidden directories using http requests, for instance if I make a http://mywebsite.com/assets/style.css
request I get the style.css
file but, I also want to have my app return files from a hidden directory, say http://mywebsite.com/.hidden-folder/file
(in this case I get a 200 response but without the file requested)
This is a kind of a new problem for me since I am not familiarized with web development, so I don’t know where to start.
Why am I asking this?
I am using certbot
for enabling https in my website and I need to allow access to .well-known/acme-challenge/
folder from web and also I am curious.
Answers:
This might help you
directory structure
├── 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"
}
This is an old question but I recently had the same issue, I used app.server.route
to basically redirect the http01 challenge that looks for files in .well-known/acme-challenge
to the correct place – in my case a relative path to a public folder. Here’s the code I added to app.py
below the instantiation of app = dash.Dash(...)
.
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)
)
This works on Dash 2.7.1.
This is similar to the post above, but the Flask/Dash differences weren’t obvious to me as a novice!
I wrote a post here about it in a bit more detail, but I think the above will suffice for anyone else who gets stuck like I did.
I think my question can be confusing, but I’ll explain it better.
What I want is to have my app return files located in hidden directories using http requests, for instance if I make a http://mywebsite.com/assets/style.css
request I get the style.css
file but, I also want to have my app return files from a hidden directory, say http://mywebsite.com/.hidden-folder/file
(in this case I get a 200 response but without the file requested)
This is a kind of a new problem for me since I am not familiarized with web development, so I don’t know where to start.
Why am I asking this?
I am using certbot
for enabling https in my website and I need to allow access to .well-known/acme-challenge/
folder from web and also I am curious.
This might help you
directory structure
├── 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"
}
This is an old question but I recently had the same issue, I used app.server.route
to basically redirect the http01 challenge that looks for files in .well-known/acme-challenge
to the correct place – in my case a relative path to a public folder. Here’s the code I added to app.py
below the instantiation of app = dash.Dash(...)
.
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)
)
This works on Dash 2.7.1.
This is similar to the post above, but the Flask/Dash differences weren’t obvious to me as a novice!
I wrote a post here about it in a bit more detail, but I think the above will suffice for anyone else who gets stuck like I did.