Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable STATIC_URL ? #108

Closed
benyanke opened this issue Nov 17, 2018 · 7 comments
Closed

Disable STATIC_URL ? #108

benyanke opened this issue Nov 17, 2018 · 7 comments

Comments

@benyanke
Copy link

Hello,

I'd like to route all my static assets through flask. Is there a way to stop the functionality provided by STATIC_URL? Currently, I have it set in my dockerfile to a long random string, effectively disabling it (since this string would never be reached on the frontend), but this feels like a hack.

image

Is there a better solution?

@tiangolo
Copy link
Owner

That's a good question. But first, is there a reason why you want Flask to serve them directly?

If you need to do anything with them in your code before serving them, they wouldn't really be static.

Check the Flask docs, they recommend having your server serve the static files and using Flask to serve them directly only during development: http://flask.pocoo.org/docs/1.0/quickstart/#static-files

If you need to use Jinja2 templates, that should go into the templates directory.

If you need to serve files that somehow you need to read in your Python code first and then serve them (for example, you need to authenticate the user first), you shouldn't put them on static, also to not confuse fellow/future developers that work with you or with your code. In that case, you can put those files in any other directory. Let's say, for example, in ./files.

@benyanke
Copy link
Author

I'll be the first to admit that my usecase is not entirely normal, but for a number of business reasons, I'm choosing to drive all requests directly through flask, to allow the highest amount of flexibility in the future. One reason is the ability to place static assets at any path easily.

@tiangolo
Copy link
Owner

tiangolo commented Jan 1, 2019

Sorry for the delay! I was busy building FastAPI.


I see... actually, there is currently no official way to disable STATIC_URL. I think it could be useful to be able to define a per-app specific nginx.conf in some way and have this image check if it exists before trying to generate one from environment variables.

That would allow you to have a completely custom nginx.conf, without the STATIC_URL parts. And the image would then just use it.

Would that work for your use case?

@tiangolo
Copy link
Owner

I just added a lot of tests for all the images, configurations, env vars, etc. To be able to refactor them knowing that I'm not breaking anything.

I'm thinking about refactoring it to allow providing a file in /app/nginx.conf and using that instead of the automatically modified/generated one. Would that solve your need?


Also, I just created a couple of alternative images with better performance and no default static serving. You might want to check them in the updated README. They might do what you need right now.

@benyanke
Copy link
Author

I will try that next time I'm in for a refactor with this client. Thanks!

@tiangolo
Copy link
Owner

tiangolo commented Feb 2, 2019

I just finished a big refactor to be able to add this feature on top.

You can now add a file /app/nginx.conf and it will be used instead of the generated one.

You can check the docs here: https://github.com/tiangolo/uwsgi-nginx-flask-docker#overriding-nginx-configuration-completely

@github-actions
Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants