1
# This file is part of the Juju GUI, which lets users view and manage Juju
2
# environments within a graphical interface (https://launchpad.net/juju-gui).
3
# Copyright (C) 2013 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU Affero General Public License version 3, as published by
7
# the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Affero General Public License for more details.
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Juju GUI server applications."""
21
from tornado import web
22
from tornado.options import options
24
from guiserver import (
31
"""Return the main server application.
33
The server app is responsible for serving the WebSocket connection, the
34
Juju GUI static files and the main index file for dynamic URLs.
36
# Set up static paths.
37
guiroot = options.guiroot
38
static_path = os.path.join(guiroot, 'juju-ui')
39
# Set up the authentication backend.
40
auth_backend = auth.get_backend(options.apiversion)
43
# Handle WebSocket connections.
44
(r'^/ws$', handlers.WebSocketHandler, {'apiurl': options.apiurl}),
45
# Handle static files.
46
(r'^/juju-ui/(.*)', web.StaticFileHandler, {'path': static_path}),
47
(r'^/(favicon\.ico)$', web.StaticFileHandler, {'path': guiroot}),
49
if options.servetests:
50
params = {'path': options.servetests, 'default_filename': 'index.html'}
51
server_handlers.append(
52
# Serve the Juju GUI tests.
53
(r'^/test/(.*)', web.StaticFileHandler, params),
55
server_handlers.append(
56
# Any other path is served by index.html.
57
(r'^/(.*)', handlers.IndexHandler, {'path': guiroot}),
59
return web.Application(
60
server_handlers, debug=options.debug, auth_backend=auth_backend)
64
"""Return the redirector application.
66
The redirector app is responsible for redirecting HTTP traffic to HTTPS.
68
return web.Application([
69
# Redirect all HTTP traffic to HTTPS.
70
(r'.*', handlers.HttpsRedirectHandler),
71
], debug=options.debug)