-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·71 lines (59 loc) · 2.47 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import sys
import config
import logging
if 'lib' not in sys.path:
# Add /lib as primary libraries directory
sys.path[0:0] = ['lib']
# Import Webapp2
import webapp2 as webapp
from webapp2 import RedirectHandler, Route
from google.appengine.dist import use_library
use_library('django', '1.2')
from google.appengine.ext.webapp import template
from google.appengine.ext import ereporter
ereporter.register_logger()
# Error Handlers
class Handle404(webapp.RequestHandler):
def handle_exception(self, exception, debug_mode):
template_values = {
'config': self.get_config('site'),
}
self.response.set_status(404)
path = os.path.join(os.path.dirname(__file__), "templates/errors", '404.html')
self.response.out.write(template.render(path, template_values))
class Handle500(webapp.RequestHandler):
def handle_exception(self, exception, debug_mode):
template_values = {
'config': self.get_config('site'),
}
self.response.set_status(500)
path = os.path.join(os.path.dirname(__file__), "templates/errors", '500.html')
self.response.out.write(template.render(path, template_values))
# Is this the development server?
debug = os.environ.get('SERVER_SOFTWARE', '').startswith('Dev')
app = webapp.WSGIApplication([
#Front-End Routes
Route('/<page:(|privacy|terms)>', 'handlers.PageHandler', name='frontend-pages'),
#App Routes
Route('/admin', 'handlers.AdminHandler', name='admin'),
Route('/dashboard', 'handlers.DashboardHandler', name='dashboard'),
Route('/edit/page/<pageid:\d+>', 'handlers.EditPageHandler', name='edit-page'),
Route('/settings', 'handlers.SettingsHandler', name='settings'),
Route('/upgrade', 'handlers.UpgradeHandler', name='upgrade'),
Route('/upload', 'handlers.UploadHandler', name='upload'),
Route('/api/<method:(scripturl|headerimageurl|getwidget|savewidget|savepageorder|deletewidget|saveoption|upgradedowngrade)>', 'handlers.AjaxApiHandler', name='api'),
Route('/listen', 'handlers.ListenHandler', name='api'),
#Facebook Routes
Route('/canvas/', 'handlers.fbCanvasHandler', name='fb-canvas'),
Route('/canvas/tab/', 'handlers.fbTabHandler', name='fb-tab')
],config=config.config,debug=debug)
# Error Handlers
app.error_handlers[404] = Handle404
#if not debug:
#app.error_handlers[500] = Handle500
# Instantiate the application
def main():
app.run()
if __name__ == '__main__':
main()