source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/rocket.py.footer @ 42095c5

mainqndtest v1.1.1
Last change on this file since 42095c5 was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 1.9 KB
Line 
1# The following code is not part of Rocket but was added to
2# web2py for testing purposes.
3
4
5def demo_app(environ, start_response):
6    global static_folder
7    import os
8    types = {'htm': 'text/html', 'html': 'text/html',
9             'gif': 'image/gif', 'jpg': 'image/jpeg',
10             'png': 'image/png', 'pdf': 'applications/pdf'}
11    if static_folder:
12        if not static_folder.startswith('/'):
13            static_folder = os.path.join(os.getcwd(), static_folder)
14        path = os.path.join(
15            static_folder, environ['PATH_INFO'][1:] or 'index.html')
16        type = types.get(path.split('.')[-1], 'text')
17        if os.path.exists(path):
18            try:
19                data = open(path, 'rb').read()
20                start_response('200 OK', [('Content-Type', type)])
21            except IOError:
22                start_response('404 NOT FOUND', [])
23                data = '404 NOT FOUND'
24        else:
25            start_response('500 INTERNAL SERVER ERROR', [])
26            data = '500 INTERNAL SERVER ERROR'
27    else:
28        start_response('200 OK', [('Content-Type', 'text/html')])
29        data = '<html><body><h1>Hello from Rocket</h1></body></html>'
30    return [data]
31
32
33def demo():
34    from optparse import OptionParser
35    parser = OptionParser()
36    parser.add_option("-i", "--ip", dest="ip", default="127.0.0.1",
37                      help="ip address of the network interface")
38    parser.add_option("-p", "--port", dest="port", default="8000",
39                      help="post where to run web server")
40    parser.add_option("-s", "--static", dest="static", default=None,
41                      help="folder containing static files")
42    (options, args) = parser.parse_args()
43    global static_folder
44    static_folder = options.static
45    print('Rocket running on %s:%s' % (options.ip, options.port))
46    r = Rocket((options.ip, int(options.port)), 'wsgi', {'wsgi_app': demo_app})
47    r.start()
48
49
50if __name__ == '__main__':
51    demo()
Note: See TracBrowser for help on using the repository browser.