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

How to serve staticfiles with flask-assets in development and production using gulp? #126

Open
rlam3 opened this issue Feb 15, 2017 · 2 comments

Comments

@rlam3
Copy link

rlam3 commented Feb 15, 2017

How to serve staticfiles with flask-assets in development and production using gulp?

I'm currently using gulp.watch to build my css/font/js etc inside a build folder to later be served via nginx.

How can I use flask-assets to serve the it properly in nginx and development?

This is how I've been serving the files in nginx

  # serve static files - each entry is a separate folder
  location ~ ^/(img|js|css)/  {
    alias /home/XXXXX/www/myapp/myapp/static/build;
    autoindex on;
    add_header Cache-Control "public";
    expires 30d;
  }

The following is how I've been serving staticfiles in my development

{# base.html #}
  <link rel="stylesheet" href="{{ url_for('static',filename='build/css/main.min.css') }}"

My only problem is that when I am serving on nginx... I have to remove the build part of the url for almost everything... This causes confusion.

I 'm looking into flask-assets to see if there is a better solution.

Thanks!

@miracle2k
Copy link
Owner

What do you mean you have to remove the build part? You don't want it in the url?

@rlam3
Copy link
Author

rlam3 commented Feb 21, 2017

The build/ is the folder destination where gulp compiles and returns the minified version of what is compiled.

Switching between production and development, I'm required to change the destingation of the build folder.

Serving from nginx production it looks like the correct way to do it:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename=‘main.min.css') }}">

It doesn't look at the static folder but at the build folder level.

Nginx Config:


  location ~ ^/(img|js|css)/  {
    alias /home/XXXX/www/app/app/static/build;
    autoindex on;
    add_header Cache-Control "public";
    expires 30d;
  }

tree:
app
—app.py
—static/
——main.styl
——build/
———css/
————main.min.css
———js/
———img/

Serving from flask development:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename=‘build/main.min.css') }}">

Problem here is that it requires me to go into the build/ folder instead of maintaining it similar to production using nginx.

How do I make a shortcut or link for static so that it recognizes that it should only look at the build/ folder level instead of the higher static folder?

Let me know if you have any tips or if Flask-Assets can help me solve this problem. Thanks!

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