getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 444 forks source link

Build-in auto server could support non-root sites better. #3715

Closed aknrdureegaesr closed 7 months ago

aknrdureegaesr commented 10 months ago

Requested Feature: (short description)

My expectation, and my suggestion for this feature request:

Related Area: (eg. tasks, compilers, configuration, templates…)

This needs change in nikola/plugins/command/auto/__init.py__. I think: Only.

Do you want to contribute this yourself as a pull request? (don’t worry about it if you don’t want to/can’t — someone else can take care of it)

I intend to provide a patch after #3722 has been merged.

Does this feature affect backwards compatibility? If yes, in what way?

I'm not here suggesting any change whatsoever to the generation of stuff in output. I only want to change the presentation of that stuff to the local browser via the Nikola development server. So this feature would not affect backwards compatibility, as far as the produced output is concerned.

This proposed change even interacts nicely with livereload (as I found out via the "Better workaround" described below).

Rationale and full description: (why should it be added to Nikola?)

The Nikola development server is more useful, the better it reflects what the production system does.

With SITE_URL = "https://example.org/blog/", Nikola has an important piece of information about the production system that it presently rather ignores.

Quick and dirty workaround

Forget about the Nikola development server for now and use a different web server to serve locally (my machine happens to run an Apache anyway). Disadvantage: No livereload.

Better workaround

Run another local server as a proxy in front of the build-in development server.

For people also using Apache, like I do, this is the config that does the trick, provided you have proxy.load and proxy_http.load both enabled:

      <Location "/blog/">
        ProxyPass http://127.0.0.1:8000/
        ProxyPassReverse http://127.0.0.1:8000/
      </Location>

This workaround is somewhat deficient for stuff that is generated on the fly by the build-in server, e.g., listings of a directory without index.html file. The links that the build-in server generates (that point at files or subdirectories) do not work through the proxy. If this is implemented, auto-generated directory listing is an area to check.

But, more importantly: This works with livereload. So I conclude livereload would not be affected by this feature, should it be implemented.

aknrdureegaesr commented 10 months ago

This is also a bug

The combination of a non-root SITE_URL and URL_TYPE = "full_path" causes the development server to simply no longer work. The links generated in output are as expected, with leading /blog/, but the development server cannot resolve those links.