annot-server/annotserver.py
changeset 43 e27c3c1c57f1
parent 13 435d5c15275a
equal deleted inserted replaced
42:926f0426ce78 43:e27c3c1c57f1
     5 
     5 
     6 
     6 
     7 from twisted.application import service, internet, strports
     7 from twisted.application import service, internet, strports
     8 from twisted.internet import reactor
     8 from twisted.internet import reactor
     9 from twisted.python.threadpool import ThreadPool
     9 from twisted.python.threadpool import ThreadPool
    10 from twisted.web import server
    10 from twisted.web import server, resource
    11 from twisted.web import resource
       
    12 from twisted.web.wsgi import WSGIResource
    11 from twisted.web.wsgi import WSGIResource
    13 from twisted.web.static import Data, File
    12 from twisted.web.static import Data, File
    14 
    13 
    15 import config
    14 import config
    16 from oscserver import OSCServerProtocol
    15 from oscserver import OSCServerProtocol
    19 
    18 
    20 
    19 
    21 WEB_PORT = 8080
    20 WEB_PORT = 8080
    22 WS_PORT = 8090
    21 WS_PORT = 8090
    23 OSC_PORT = 9090
    22 OSC_PORT = 9090
       
    23 
       
    24 class BaseRedirect(resource.Resource):
       
    25     isLeaf = True
       
    26     def render_GET(self, request):
       
    27         request.redirect(request.URLPath().child('p/'))
       
    28         return ""
    24 
    29 
    25 def make_service(conn, debug=False):
    30 def make_service(conn, debug=False):
    26 
    31 
    27     s = service.MultiService()
    32     s = service.MultiService()
    28     # Create and start a thread pool,
    33     # Create and start a thread pool,
    52     rootWs = Data("", "text/plain")
    57     rootWs = Data("", "text/plain")
    53 
    58 
    54     rootWs.putChild("broadcast", wsResource)
    59     rootWs.putChild("broadcast", wsResource)
    55     rootWs.putChild("annot", wsAnnotResource)
    60     rootWs.putChild("annot", wsAnnotResource)
    56 
    61 
    57 
       
    58     webResource = resource.Resource()
    62     webResource = resource.Resource()
       
    63     webResource.putChild("",BaseRedirect())
    59     webResource.putChild(getattr(config,'STATIC_URL').lstrip('/'), File(getattr(config,'STATIC_ROOT')))
    64     webResource.putChild(getattr(config,'STATIC_URL').lstrip('/'), File(getattr(config,'STATIC_ROOT')))
    60     # Create the WSGI resource
    65     # Create the WSGI resource
    61     wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, app)
    66     wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, app)
    62     webResource.putChild('p', wsgiAppAsResource)
    67     webResource.putChild('p', wsgiAppAsResource)
    63 
    68