view bin/homepageConfig @ 1365:a6ca5e87ab3e

a bit more usage of runHandler in timeline element Ignore-this: 7f8b7ddd8c7501b8231755c4a172ad2c
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 06 Jun 2016 07:07:19 +0000
parents 44558087d3f6
children 15f296550447
line wrap: on
line source

#!bin/python
from run_local import log
from rdflib import RDF, URIRef
from light9 import networking, showconfig
from light9.namespaces import L9
from urlparse import urlparse
from urllib import splitport

from light9.rdfdb.syncedgraph import SyncedGraph
from twisted.internet import reactor

graph = showconfig.getGraph()

netHome = graph.value(showconfig.showUri(), L9['networking'])
print "listen %s;" % splitport(urlparse(graph.value(netHome, L9['webServer'])).netloc)[1]

def location(path, server):
    print """
    location /%(path)s/ {

      # for websocket
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;

      proxy_pass %(server)s;
      rewrite /[^/]+/(.*) /$1 break;
    }""" % vars()

for role, server in sorted(graph.predicate_objects(netHome)):
    if not server.startswith('http') or role == L9['webServer']:
        continue
    path = graph.value(role, L9['urlPath'])
    if not path:
        continue
    server = server.rstrip('/')
    location(path, server)



showPath = showconfig.showUri().split('/', 3)[-1]
print """
    location /%(path)s {
      root %(root)s;
    }""" % {'path': showPath,
            'root': showconfig.root()[:-len(showPath)]}