question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flask, Build, and accessing the Static directories

See original GitHub issue

Hi there. I’m having an awful time trying to figure out what I’ve messed up.

The result of running npm run build is that I have a production directory at foo/app/build/. This includes all of the good stuff, e.g. static/, index.html, manifest.json, etc. My flask app is served from foo/__init__.py and declared with app = Flask(__name__, static_folder="./app/build/static", template_folder="./app/build").

As usual, the index.html in app/build is the entry point, and it loads React at /static/js/main.<hash>.js. This works as expected. So does the /static/css/* files and so forth. What I mean by that is that if I try to serve localhost from the build, then I can visit http://localhost:5000/static/js/main.<hash>.js and it will load the minified js.

However, nothing else in foo/app/build can be seen and loaded, even though the server is returning 200s when I request the root:

@a.app.route('/', methods=['GET'])
def index():
    return render_template('index.html')

@a.app.route('/<path:path>', methods=['GET'])
def any_root_path(path):
    return render_template('index.html')

This includes the inex.html, service-worker.js, the favicon.ico, and the manifest.json. If I run npm start and use a proxy to talk to the client at port 3000 and the server at port 5000 (on localhost), then everything works. That of course won’t fly for production.

Any idea what’s going on?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
CharlyJazzcommented, Mar 6, 2018
0reactions
cinjoncommented, Feb 19, 2018

It ended up being an unrelated issue somewhere else in the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to serve static files in Flask - python
Basically you just need a "static" folder at the root of your package, and then you can use url_for('static', filename='foo.bar') or directly link...
Read more >
Serving Static Files with Flask
Static files in Flask have a special route. All application URLs that begin with "/static", by convention, are served from a folder located...
Read more >
How Do You Serve Static Files in Flask?
You need to create a folder called static in your application's root directory to store all your static files. Then you can use...
Read more >
Static Files — Flask Documentation (2.2.x)
Static Files¶ ; static view that takes a path relative to the ; flaskr/static directory and serves it. The ; base.html template already...
Read more >
Flask static files (Example) - Python Tutorial
The URL of the special endpoint static is used to generate a static file. In your programs directory, create a new directory named...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found