-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.py
69 lines (58 loc) · 2.22 KB
/
request.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
import os
# specify the name of your settings module
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import datastore
from beaker.middleware import SessionMiddleware
from controllers import *
application = webapp.WSGIApplication([
("/(news.atom)?", HomePage),
("/about", AboutPage),
("/faq", FAQPage),
("/other", OtherPage),
("/sundayn(?:/([0-9]+))?(?:/([^/]+))?", SundayNPage),
("/browse(.rss)?", BrowsePage),
("/(userlevels)", BrowsePage),
("/search", AdvancedSearchPage),
("/unread", UnreadPage),
("/featured(.atom)?", FeaturedPage),
("/authors", AuthorActivityPage),
("/submit", SubmitPage),
("/login", LoginPage),
("/logout", LogoutPage),
("/verify", VerifyPage),
("/user(?:/([^/]+)(?:/([^/]+))?)?", UserInfoPage),
("/whoswho", WhosWhoPage),
("/suggest_tags", SuggestTagsPage),
("/admin/modqueue", ModerationQueuePage),
("/admin/newspost", NewsPostPage),
("/map/([0-9]+)(?:/([^/]+))?", MapRedirectPage),
("/([0-9]+)/mapdata", MapDataHandler),
("/([0-9]+)/commentdata", CommentDataHandler),
("/([0-9]+)(?:/([^/]+))?", MapPage),
("/api/maps", MapFirehoseHandler),
("/api/comments", CommentFirehoseHandler),
("/preview", PreviewPage)
])
def www_redirect(wsgi_app):
def do_www_redirect(env, start_response):
if env["HTTP_HOST"] == "nmaps.net":
newurl = "http://www.nmaps.net%s%s" % (env["SCRIPT_NAME"],
env["PATH_INFO"])
query_str = env.get("QUERY_STRING", "")
if query_str:
newurl += "?%s" % query_str
start_response("301 Moved Permanently", [("Location", newurl)])
return ["<html><head><title>301 Moved Peramanently</title></head>",
"<body><a href=\"%s\">Click Here</a></body></html>" % newurl]
else:
return wsgi_app(env, start_response)
return do_www_redirect
application = SessionMiddleware(application, type="google", table_name="Session",
cookie_expires=False)
application = www_redirect(application)
def main():
util.run_wsgi_app(application)
if __name__ == "__main__":
main()