0

I'm preparing a package developed in-house to be delivered to a customer. During development in house, we've used copies of common JavaScript libraries (jquery, openlayers, underscore) in our code repository, and that works. However, in the delivered system, management feels (and I agree) that if we deliver our 'own copies' of these common libraries then we become responsible for them.

Consequently I'm trying to rework the system so that it serves these libraries from /usr/share/javascript, which is where the OS (Ubuntu) puts them. This works fine when the package is deployed with Apache; however it doesn't work when run from

python manage.py runserver

What do I need to add to my settings.py so that runserver will serve files from /usr/share/javascript on the URL

http://localhost:8000/javascript/ ?

How do I ensure that those files are not collected by 'collectstatic'?

Thanks!

Simon Brooke
  • 386
  • 4
  • 7
  • Built-in `runserver` serves static assets in `STATIC_ROOT` and `STATIC_DIRS` when `DEBUG=True` and only `STATIC_ROOT` when `DEBUG=False`. Therefore you must add your OS directories to `STATIC_DIRS` but in any case they will be collected. Why are you trying to prevent them from being collected? – Selcuk Mar 12 '15 at 12:15
  • If we deliver them, we're responsible for them. If they're loaded from the package-manager, Ubuntu (Canonical Ltd) are responsible for them. Also, if there are security updates, then running `apt-get update` on the server will fix them without our having to rebuild and redeploy. – Simon Brooke Mar 12 '15 at 13:27
  • Apache aliases will take care of it but why is it important to make it work with development server? Are you running runserver on the production server? – Selcuk Mar 12 '15 at 13:44
  • The problem is that you cannot set `STATIC_URL` to `/` in `settings.py` - you get "Directory indexes are not allowed here." So although I've added `/var/www` to `STATIC_DIRS`, it still wants to serve them on `http://localhost:8000/static/javascript/` – Simon Brooke Mar 12 '15 at 13:53

1 Answers1

0

After a lot of messing about, I have a solution; but it's complicated and ugly. It wasn't possible to make runserver emulate the apache environment, or apache emulate the runserver environment. So to make both Apache and runserver work with package-manager provided javascript libraries, the following key changes are required:

  1. Add /usr/share to STATICFILES_DIRS in settings.py, but
  2. remove it before running collectstatic
  3. add Options FollowSymLinks to the apache configuration for /var/www/static, and
  4. symlink /usr/share/javascript into /var/www/static

So, for clarity, the Apache configuration contains

Alias /static/ /var/www/static/ <Directory /var/www/static> Options FollowSymLinks Order deny, allow Allow from all </Directory>

settings.py contains

STATIC_ROOT = os.path.join(BASE_DIR, '/myapp/static') STATICFILES_DIRS = ( '/usr/share', ) STATIC_URL = '/static/'

Before running collectstatic, /usr/share is REMOVED from settings.py, otherwise you collect a whole lot of things you don't want to collect.

I'm not saying this is an ideal solution, but it's working.

Simon Brooke
  • 386
  • 4
  • 7