blob: 388fb2b721cc6849a01c05107f6294d8a45d5f96 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2016 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""Main program for Monorail.
5
6Monorail is an issue tracking tool that is based on the code.google.com
7issue tracker, but it has been ported to Google AppEngine and Google Cloud SQL.
8"""
9from __future__ import print_function
10from __future__ import division
11from __future__ import absolute_import
12
13import os
14import six
15
16import flask
17import google.appengine.api
18import google.cloud.logging
19
20# Fix imports before importing gae_ts_mon.
21import import_utils
22
23import_utils.FixImports()
24
25import gae_ts_mon
26
27import registerpages
28from framework import sorting
29from redirect import redirect
30from services import service_manager
31
32if os.getenv('GAE_ENV') == 'standard':
33 # If this isn't a local server, set up cloud logging.
34 client = google.cloud.logging.Client()
35 client.setup_logging()
36
37if six.PY3:
38 # https://github.com/GoogleCloudPlatform/appengine-python-standard/issues/70
39 import functools
40 from google.appengine.api import memcache
41 unpickler = functools.partial(six.moves.cPickle.Unpickler, encoding='bytes')
42 memcache.setup_client(memcache.Client(unpickler=unpickler))
43
44services = service_manager.set_up_services()
45sorting.InitializeArtValues(services)
46
47app = flask.Flask(__name__)
48app.wsgi_app = google.appengine.api.wrap_wsgi_app(app.wsgi_app)
49
50redirect_app = redirect.GenerateRedirectApp()
51app.wsgi_app = redirect.RedirectMiddleware(app.wsgi_app, redirect_app.wsgi_app)
52
53registerpages.ServletRegistry().Register(services, app)
54registerpages.RegisterEndpointsUrls(app)
55registerpages.RegisterTeardown(app)
56
57gae_ts_mon.initialize_prod(app)