Thread: Queries regarding staticfiles | pgarchives

Queries regarding staticfiles | pgarchives

From
Sahil Harpal
Date:
Hello,
I have following queries related to staticfiles:
  • Why do we have /media-archives/... URL for CSS files? [https://github.com/postgres/pgarchives/blob/master/django/archives/mailarchives/templates/base.html#L18] Such folder is not present in the project. We have a folder named media which contains all static files. Can I change all /media-archives/ to /media/ ? Also the css_map that dynamic_css() method is using and in the css files for specifying path to images, contain /media/ and not /media-archives/.
  • What is the use case of that dynamic_css() method?
  • CSS and images will reflect on the HTML pages when I set STATIC_URL = "/media/" and change all media-archives to media. Also I need to add 'django.contrib.staticfiles' in the INSTALLED_APPS.
  • In the main.css also many things are missing.
    I have attached the main.css present in the GitHub and main.css that actual pgarchives is using. Why do we have such differences in the code?
Thanks,
Sahil Harpal
Attachment

Re: Queries regarding staticfiles | pgarchives

From
Magnus Hagander
Date:


On Tue, Jun 14, 2022 at 2:43 PM Sahil Harpal <sahilharpal1234@gmail.com> wrote:
Hello,
I have following queries related to staticfiles:

Because it runs on the same hostname as www.postgresql.org, and otherwise there would be a potential conflict. The folder /media/ is in the filesystem, and should be served up as /media-static/ on http.

 
  • What is the use case of that dynamic_css() method?

It is to reduce the number of files in a quick and hacky way. We had too many different CSS files and this is one way to serve them up under a single URL to make things faster.
 
  • CSS and images will reflect on the HTML pages when I set STATIC_URL = "/media/" and change all media-archives to media. Also I need to add 'django.contrib.staticfiles' in the INSTALLED_APPS.

We don't use staticfiles.

  • In the main.css also many things are missing.
    I have attached the main.css present in the GitHub and main.css that actual pgarchives is using. Why do we have such differences in the code?

What do you mean "present in the github" and the one that's in pgarchives? Where is it on github and where do you see it in pgarchives?  

--

Re: Queries regarding staticfiles | pgarchives

From
Sahil Harpal
Date:

Because it runs on the same hostname as www.postgresql.org, and otherwise there would be a potential conflict. The folder /media/ is in the filesystem, and should be served up as /media-static/ on http.

What am I supposed to do to resolve 404 I am getting for these urls?
image.png

We don't use staticfiles.

So, why are CSS and images not loading properly. I have attached the screenshot of the home screen with default settings. What do I need to configure to resolve this?
image.png

What do you mean "present in the github" and the one that's in pgarchives? Where is it on github and where do you see it in pgarchives?  
 
main.css file
The CSS that is being loaded for this page: https://www.postgresql.org/list/ (actual CSS that pgarchives using) I compared this by inspecting components in the browser.

--
Sahil Harpal
Attachment

Re: Queries regarding staticfiles | pgarchives

From
Magnus Hagander
Date:


On Tue, Jun 14, 2022 at 6:02 PM Sahil Harpal <sahilharpal1234@gmail.com> wrote:

Because it runs on the same hostname as www.postgresql.org, and otherwise there would be a potential conflict. The folder /media/ is in the filesystem, and should be served up as /media-static/ on http.

What am I supposed to do to resolve 404 I am getting for these urls?
image.png


As I said, you need to make the folder /media/ be served up as /media-static/. This is configuration in your webserver.


 

What do you mean "present in the github" and the one that's in pgarchives? Where is it on github and where do you see it in pgarchives?  
 
main.css file
The CSS that is being loaded for this page: https://www.postgresql.org/list/ (actual CSS that pgarchives using) I compared this by inspecting components in the browser.

 
Um. There is no reference from https://www.postgresql.org/list/ to main.css in media-archives that I can see?

--
Attachment

Re: Queries regarding staticfiles | pgarchives

From
Sahil Harpal
Date:
On Wed, 15 Jun 2022 at 02:52, Magnus Hagander <magnus@hagander.net> wrote:
As I said, you need to make the folder /media/ be served up as /media-static/. This is configuration in your webserver.
 
Could you please help me to do this? Like where and what I need to change.

Um. There is no reference from https://www.postgresql.org/list/ to main.css in media-archives that I can see?

Yeah, with the help of /dyncss/ the base.css = (main.css+normalize.css) of pgweb gets loaded after visiting /list/.
Now I am just confused about what exactly happens when someone opens  https://www.postgresql.org/list/ in the browser? How is HTML loading? If it is using CSS files of pgweb then why do we have CSS files in the /media/css/ of pgarchives :(

Re: Queries regarding staticfiles | pgarchives

From
Magnus Hagander
Date:
On Wed, Jun 15, 2022 at 5:38 AM Sahil Harpal <sahilharpal1234@gmail.com> wrote:
On Wed, 15 Jun 2022 at 02:52, Magnus Hagander <magnus@hagander.net> wrote:
As I said, you need to make the folder /media/ be served up as /media-static/. This is configuration in your webserver.
 
Could you please help me to do this? Like where and what I need to change.

That depends on what webserver you're using. For example, in uwsgi you'd add something like:
static-map=/media-archives=/some/where/pgarchives/django/media 

For nginx, it'd be something like:
        location /media-archives/ {
                alias /some/where/pgarchives/django/media/;
        }

 
Um. There is no reference from https://www.postgresql.org/list/ to main.css in media-archives that I can see?

Yeah, with the help of /dyncss/ the base.css = (main.css+normalize.css) of pgweb gets loaded after visiting /list/.
Now I am just confused about what exactly happens when someone opens  https://www.postgresql.org/list/ in the browser? How is HTML loading? If it is using CSS files of pgweb then why do we have CSS files in the /media/css/ of pgarchives :(

Oh. Yes, anything outside of /list/ is loaded from pgweb. The dyncss is one of them. And yes, this is kind of a hacky and terrible way, but that's how it is right now. Certain parts of them have to be kept in sync.

We need them separately because the same pgarchives code is also run standalone, for our private archives. And in that scenario, there is no pgweb involved.

--

Re: Queries regarding staticfiles | pgarchives

From
Sahil Harpal
Date:


On Wed, 15 Jun 2022 at 22:43, Magnus Hagander <magnus@hagander.net> wrote:
That depends on what webserver you're using. For example, in uwsgi you'd add something like:
static-map=/media-archives=/some/where/pgarchives/django/media 

For nginx, it'd be something like:
        location /media-archives/ {
                alias /some/where/pgarchives/django/media/;
        }

I tried this, but still, it is showing 404.
I created a .ini file and added the following values. and instead of running the server using runserver command I am using uwsgi.

[uwsgi]
http = localhost:8000
wsgi-file = archives/wsgi.py
static-map = /media-archives=/pgarchives/django/media 

Am I missing anything here?

Oh. Yes, anything outside of /list/ is loaded from pgweb. The dyncss is one of them. And yes, this is kind of a hacky and terrible way, but that's how it is right now. Certain parts of them have to be kept in sync.

We need them separately because the same pgarchives code is also run standalone, for our private archives. And in that scenario, there is no pgweb involved.

Okay, so let's say if I want to make some changes in https://www.postgresql.org/list/, https://www.postgresql.org/list/pgsql-admin/, https://www.postgresql.org/list/pgsql-admin/2022-06/ etc. In which file should I make changes? main.css of pgweb or pgarchives or both (since pgarchives can also run standalone)? 

Thanks,
Sahil Harpal

Re: Queries regarding staticfiles | pgarchives

From
Magnus Hagander
Date:
On Thu, Jun 16, 2022 at 4:05 PM Sahil Harpal <sahilharpal1234@gmail.com> wrote:


On Wed, 15 Jun 2022 at 22:43, Magnus Hagander <magnus@hagander.net> wrote:
That depends on what webserver you're using. For example, in uwsgi you'd add something like:
static-map=/media-archives=/some/where/pgarchives/django/media 

For nginx, it'd be something like:
        location /media-archives/ {
                alias /some/where/pgarchives/django/media/;
        }

I tried this, but still, it is showing 404.
I created a .ini file and added the following values. and instead of running the server using runserver command I am using uwsgi.

[uwsgi]
http = localhost:8000
wsgi-file = archives/wsgi.py
static-map = /media-archives=/pgarchives/django/media 

Am I missing anything here?

Assuming your pgarchives checkout is in /pgarchives/ that seems like it would be correct.

I personally use the chdir setting in uwsgi rater than the wsgi-file, but that shouldn't affect the static mapping.


Oh. Yes, anything outside of /list/ is loaded from pgweb. The dyncss is one of them. And yes, this is kind of a hacky and terrible way, but that's how it is right now. Certain parts of them have to be kept in sync.

We need them separately because the same pgarchives code is also run standalone, for our private archives. And in that scenario, there is no pgweb involved.

Okay, so let's say if I want to make some changes in https://www.postgresql.org/list/, https://www.postgresql.org/list/pgsql-admin/, https://www.postgresql.org/list/pgsql-admin/2022-06/ etc. In which file should I make changes? main.css of pgweb or pgarchives or both (since pgarchives can also run standalone)? 

Annoyingly enough, both. 

--