annotate bin/homepageConfig @ 1217:e703b3434dbd

websocket and web cleanup Ignore-this: ac6bd0444bc03ee79ce71c4aa7740bc0
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 08 Jun 2015 02:08:25 +0000
parents 0d295af23c4b
children 70f42f9d6e04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1215
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
1 #!bin/python
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
2 from run_local import log
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
3 from rdflib import RDF, URIRef
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
4 from light9 import networking, showconfig
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
5 from light9.namespaces import L9
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
6
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
7 from light9.rdfdb.syncedgraph import SyncedGraph
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
8 from twisted.internet import reactor
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 graph = SyncedGraph(networking.rdfdb.url, "homepageConfig")
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
11
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
12 @graph.initiallySynced.addCallback
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
13 def printConfig(result):
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
14 with graph.currentState() as current:
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
15 netHome = current.value(showconfig.showUri(), L9['networking'])
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
16 for role, server in current.predicate_objects(netHome):
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
17 if not server.startswith('http'):
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
18 continue
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
19 path = current.value(role, L9['urlPath'])
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
20 server = server.rstrip('/')
1217
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
21 print """
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
22 location /%(path)s {
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
23
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
24 # for websocket
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
25 proxy_http_version 1.1;
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
26 proxy_set_header Upgrade $http_upgrade;
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
27 proxy_set_header Connection "upgrade";
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
28 proxy_set_header Host $host;
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
29
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
30 proxy_pass %(server)s;
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
31 rewrite /[^/]+/(.*) /$1 break;
e703b3434dbd websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents: 1215
diff changeset
32 }""" % vars()
1215
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
33
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
34 reactor.stop()
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
35
0d295af23c4b new nginx router
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
36 reactor.run()