-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·37 lines (30 loc) · 1.08 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
#!/usr/bin/env python
import wsgiref.handlers
from shifteleven import handlers
from shifteleven.handlers import project
from google.appengine.ext import webapp
context = '/v1'
class SiteRedirector(webapp.RequestHandler):
def get(self):
self.redirect(context)
class MockHTTPMethodMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
method = webapp.Request(environ).get('_method')
if method:
environ['REQUEST_METHOD'] = method.upper()
return self.app(environ, start_response)
def main():
application = webapp.WSGIApplication([
('/', SiteRedirector),
(context, handlers.MainHandler),
('%s/projects' % context, project.ProjectCollectionHandler),
('%s/projects/new' % context, project.NewProjectHandler),
('%s/projects/(\d+)' % context, project.ProjectHandler),
('%s/projects/(\d+)/edit' % context, project.EditProjectHandler)
],
debug=True)
wsgiref.handlers.CGIHandler().run(MockHTTPMethodMiddleware(application))
if __name__ == '__main__':
main()