def getAppURLs(serverName): """ :: Str -> [] Given a domain like foo.webappworkshop.com, this builds a map of the urls. :param serverName: the SERVER_NAME from wsgi :return: the imported root module, or None """ universal_api = REST.urlMap( [ (r"/api/g/?$", { REST.get: CRUD.list_grids, REST.post: CRUD.create_grid }), (r"/api/g/(?P<table>\w+)/?$", { REST.get: CRUD.get_grid_meta, #put: CRUD.put_grid_meta, REST.post: CRUD.create_grid_row, #delete: CRUD.delete_grid }), (r"/api/g/(?P<table>\w+)/data/?$", { REST.get: CRUD.get_grid_data }), (r"/api/g/(?P<table>\w+)/(?P<id>\d+)/?$", { REST.get: CRUD.get_grid_row, REST.put: CRUD.put_grid_row, REST.delete: CRUD.delete_grid_row }), ]) if serverName.startswith("localhost"): res = [] else: res = universal_api cut = -1 if serverName.endswith("localhost") else -2 appName = '.'.join(serverName.split('.')[:cut]) logging.debug("appName is %r" % appName) if os.path.exists("app/%s/%s.py" % (appName, appName)): modname = 'app.%s.%s' % (appName, appName) exec 'import %s' % modname extras = getattr(eval(modname), 'urls', []) res.extend(extras) else: logging.debug("%s is not a valid app" % serverName) return res
""" URL map for tangentcode. """ from app.tangentcode import editor import REST urls = REST.urlMap([ (r"/$", { REST.get: editor.showEditor }), ])
class OutVar: value = None def main(req, res): """ :param weblib.Request req :param weblib.Response res """ out = OutVar() if LOGIN.check(req, res, out): res.write( """ <!doctype html> <html> <head> <title>webAppWorkshop</title> </head> <body> <h1>Hello, %s</h1> <p>Greetings from <strong>%s</strong>!</p> </body> </html> """ % ( out.value.nickname(), req.host )) urls = REST.urlMap([ (r"/$", { REST.get: main }), ])