forked from faisalraja/app-engine-starter
/
main.py
36 lines (29 loc) · 1.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
This is designed more for backend developers building quick prototypes
If you want to optimize your frontend you should probably start with
using less and having a script the merge and compress them
"""
import logging
import webapp2
import config
import routes
from google.appengine.ext import deferred, ndb
from web import errors
from lib import basehandler
app = webapp2.WSGIApplication(debug=basehandler.IS_DEV, config=config.webapp2_config, routes=routes.get_routes())
# If you want dynamic custom error handlers use below
# or just comment it out. This is useful for gracefully showing errors to users
class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter):
def __call__(self, request, response, exception):
request.route_args = {
'exception': exception
}
logging.exception(exception)
handler = self.handler(request, response)
return handler.get()
app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler)
app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler)
app.error_handlers[503] = Webapp2HandlerAdapter(errors.Error503Handler)
app.error_handlers[500] = Webapp2HandlerAdapter(errors.Error500Handler)
# Make sure all ndb async futures finish
app = ndb.toplevel(app)