def make_app(): application = URLDispatcher() js_app = DirectoryApp(os.path.join(here, 'static/js')) css_app = DirectoryApp(os.path.join(here, 'static/css')) img_app = DirectoryApp(os.path.join(here, 'static/img')) application.add_url('js', '/js/*', js_app) application.add_url('css', '/css/*', css_app) application.add_url('img', '/img/*', img_app) application.add_url('page', '/{page_name}', page_view) application.add_url('page_edit', '/{page_name}/edit', page_edit) application.add_url('top', '/', HTTPFound(location='FrontPage')) return application
def wsgi_factory(): # pragma: no cover morepath.autoscan() if os.getenv("RUN_ENV") == "production": ProductionApp.commit() app = ProductionApp() elif os.getenv("RUN_ENV") == "test": TestApp.commit() app = TestApp() else: App.commit() app = App() index = FileApp("build/index.html") static = DirectoryApp("build", index_page=None) setup_db(app) @webob.dec.wsgify def morepath_with_static_absorb(request): popped = request.path_info_pop() if popped == "api": return request.get_response(app) elif popped == "static": return request.get_response(static) else: return request.get_response(index) return morepath_with_static_absorb
def make_staticdir(global_conf, path, index_page='index.html', hide_index_with_redirect=False): """ Return a WSGI application that serves a directory (configured with path) """ return DirectoryApp(path=path, index_page='index.html', hide_index_with_redirect=False)
def main(): from paste import httpserver from paste.cascade import Cascade from webob.static import DirectoryApp, FileApp # Create a cascade that looks for static files first, then tries the webapp static_app = DirectoryApp("static") fullapp = Cascade([static_app, app]) httpserver.serve(fullapp, host='localhost', port='8070')
def register_statics(self, module_name, plugged): if plugged['modules'][module_name]['statics'] is None: statics_app = DirectoryApp(self.public_path) static_middlewares = self.options.get('static_middlewares', []) for middleware in static_middlewares: statics_app = middleware(statics_app, self.public_path) plugged['modules'][module_name]['statics'] = statics_app
def __init__(self, req, link, data, **config): super(NMaaS_Network_Controller_RESTAPI, self).__init__(req, link, data, **config) self.nmaas_network_controller_app = data[ nmaas_network_controller_instance_name] path = "%s/html/" % PATH print path self.static_app = DirectoryApp(path)
def __init__(self, req, link, data, **config): super(NMaaS_RESTAPI, self).__init__(req, link, data, **config) self.nmaas_network_controller_app = data[ nmaas_network_controller_instance_name] path = "%s/html/" % PATH print path self.static_app = DirectoryApp(path) self.nmaas = self.nmaas_network_controller_app self.log = l.getLogger(self.__class__.__name__, self.nmaas.debug_level)
class StaticsController(TGController): _directory_app = DirectoryApp(STATICS_PATH) @expose() def _default(self, *args): new_req = request.copy() to_pop = len(new_req.path_info.strip('/').split('/')) - len(args) for i in range(to_pop): new_req.path_info_pop() return new_req.get_response(self._directory_app)
def add_static_route(self, route, static_dir): """ Add a static directory as a route """ if route not in self.static_routes: static_path = AppLocation.get_section_data_path('remotes') / static_dir if not static_path.exists(): log.error('Static path "%s" does not exist. Skipping creating static route/', static_path) return self.static_routes[route] = DirectoryApp(str(static_path.resolve()))
def application(): """TODO""" mount_points = { 'index': PREFFIX, 'assets': '/'.join([PREFFIX, 'assets']), 'packages': '/'.join([PREFFIX, 'packages']), } paths = { 'asssets': ASSETS_PATH, 'packages': PACKAGES_PATH, 'templates': TEMPLATES_PATH } index = Index(paths['templates']) filters = { # filter packages by extension 'packages': re.compile( r'\.({})$'.format(PACKAGES_EXT.replace('.', r'\.')), re.I), # filter static files by extension 'assets': re.compile( r'\.({})$'.format(ASSETS_EXT.replace('.', r'\.')), re.I), } handlers = { 'index': FancyCollectionHandler(index, mount_points, paths), 'packages': filter_path( # pylint: disable=no-value-for-parameter DirectoryApp(paths['packages'], index_page=None), filters['packages']), 'assets': filter_path( # pylint: disable=no-value-for-parameter DirectoryApp(paths['assets'], index_page=None), filters['assets']), } routes = [ (route, {'GET': handlers[resource]}) for resource, route in mount_points.items() ] return Selector(mappings=routes)
def __init__(self, req, link, data, **config): super(GUIServerController, self).__init__(req, link, data, **config) #Get reference to Web app to redirect path = "%s/html/" % PATH self.static_app = DirectoryApp(path) #Get reference to Proxy instance self.proxy = data['Proxy'] self.mainapp = data['app']
def command_serve(parser, options, ags): '''Starts a local server''' static_app = DirectoryApp("static", index_page=None) # Create a cascade that looks for static files first, # then tries the other apps cascade_app = ExceptionMiddleware(Cascade([static_app, fever_app, frontend_app])) httpd = make_server('localhost', options.port, cascade_app) print 'Serving on http://localhost:%s' % options.port try: httpd.serve_forever() except KeyboardInterrupt: print 'Interrupted by user'
def main(): options, args = parser.parse_args() if options.clear: if os.path.exists(options.dir): print 'Deleting %s' % options.dir shutil.rmtree(options.dir) from cutout.sync import Application db_app = Application(dir=options.dir, include_syncclient=True) from webob.static import DirectoryApp from paste.urlmap import URLMap map = URLMap() map['/'] = DirectoryApp(os.path.join(here, 'cutout', 'tests', 'syncclient')) map['/db'] = TestAuthMiddleware(db_app) from paste.httpserver import serve serve(map, host=options.host, port=int(options.port))
def command_serve(self, options, args): '''Starts a local server''' static_app = DirectoryApp("static", index_page=None) # Create a cascade that looks for static files first, # then tries the other apps cascade_app = ExceptionMiddleware(cascade.Cascade([static_app, fever.setup_app(), frontend.setup_app()])) address = '0.0.0.0' if options.allow_remote_access else 'localhost' httpd = make_server(address, options.port, cascade_app) print 'Serving on http://%s:%s' % (address, options.port) try: httpd.serve_forever() except KeyboardInterrupt: print 'Interrupted by user'
def main(): options, args = parser.parse_args() if options.clear: if os.path.exists(options.dir): print 'Deleting %s' % options.dir shutil.rmtree(options.dir) mapper = URLMap() for arg in args: if '=' in arg: path, dir = arg.split('=', 1) else: path, dir = '/', arg mapper[path] = DirectoryApp(dir) from cutout.sync import Application db_app = Application(dir=options.dir, include_syncclient=True) mapper['/sync'] = db_app serve(mapper, host=options.host, port=int(options.port))
def run(): # pragma: no cover morepath.autoscan() index = FileApp('static/index.html') static = DirectoryApp('static') app = App() @webob.dec.wsgify def morepath_with_static_absorb(request): popped = request.path_info_pop() if popped == 'api': return request.get_response(app) elif popped == 'static': return request.get_response(static) else: return request.get_response(index) morepath.run(morepath_with_static_absorb)
def __call__(self, req): if req.path_info_peek() != "static": return req.get_response(self.app) # strip "/static" req.path_info_pop() # statically serve the directory if isinstance(self.static, string_types): return req.get_response(DirectoryApp(self.static)) # otherwise, load resource from package package, resource_path = self.static resource = os.path.join(resource_path, *req.path_info.split('/')) if not pkg_resources.resource_exists(package, resource): return HTTPNotFound(req.path_info) content_type, content_encoding = mimetypes.guess_type(resource) return Response(body=pkg_resources.resource_string(package, resource), content_type=content_type, content_encoding=content_encoding)
def server(): graphql = graphql_wsgi(StarWarsSchema) static = DirectoryApp('build', index_page=None) index = FileApp('index.html') graphiql = FileApp('graphiql.html') @wsgify def mount_graphql(request): if request.path_info_peek() == '': return request.get_response(index) if request.path_info_peek() == 'graphiql': return request.get_response(graphiql) popped = request.path_info_pop() if popped == 'graphql': return request.get_response(graphql) elif popped == 'static': return request.get_response(static) raise HTTPNotFound() server = make_server('127.0.0.1', 5000, mount_graphql) print "Python GraphQL server running on http://127.0.0.1:5000/graphql" print "React with Relay UI available on http://127.0.0.1:5000" server.serve_forever()
def __init__(self, req, link, data, **config): super(WSController, self).__init__(req, link, data, **config) self.main_app = data[main_app_instance_name] path = "%s/html/" % PATH self.static_app = DirectoryApp(path)
def __init__(self, req, link, data, **config): super(GUIServerController, self).__init__(req, link, data, **config) path = "%s/html/" % PATH self.static_app = DirectoryApp(path)
def __init__(self, req, link, data, **config): super(NetworkMonitorController, self).__init__(req, link, data, **config) path = "%s/gui/" % PATH self.static_app = DirectoryApp(path) self.multipath_app = data['multipath_app']
def register_statics(self, module_name, plugged): if plugged['modules'][module_name]['statics'] is None: plugged['modules'][module_name]['statics'] = DirectoryApp( self.public_path)
def __init__(self, req, link, data, **config): super(PortStatsController, self).__init__(req, link, data, **config) self.port_stats_app = data['port_stats_app'] self.static_app = DirectoryApp(os.path.dirname(__file__) + '/public/')
def main(): static_app = DirectoryApp(".", index_page=None) # Create a cascade that looks for static files first, then tries the webapp app = Cascade([static_app, web_app]) httpserver.serve(app, host='127.0.0.1', port='8080')
from webob.static import DirectoryApp app = DirectoryApp(".")
def __init__(self, req, link, data, **config): super(GUIServerController, self).__init__(req, link, data, **config) path = '%s/html/' % os.path.dirname(__file__) self.static_app = DirectoryApp(path)
def __init__(self, req, link, data, **config): super(HaecController, self).__init__(req, link, data, **config) self.haec_api_app = data['haec_api_app'] path = "%s/html/" % PATH self.static_app = DirectoryApp(path)
from wsgiref.simple_server import make_server from webob.dec import wsgify from webob.static import DirectoryApp import urlparse import imp import os path_httpd_root = "" # serve files for / path_httpd_root = os.path.abspath(path_httpd_root) directory_root_app = DirectoryApp(path_httpd_root) # serve files for /_webhdf path_test = os.path.dirname(os.path.abspath(__file__)) path_webhdf = os.path.normpath(os.path.join(path_test, "..", "webhdf")) directory_webhdf_app = DirectoryApp(path_webhdf) # serve webhdf application webhdf = imp.load_source("webhdf", os.path.join(path_webhdf, "webhdf.wsgi")) webhdf.root_local = path_httpd_root webhdf.url_webhdf = "/_webhdf/webhdf.wsgi" webhdf_app = webhdf.application # main application @wsgify def application(req): path_url = req.path_info path_local = os.path.normpath(os.path.join(path_httpd_root, req.path_info.lstrip('/'))) if path_url == webhdf.url_webhdf: return webhdf_app elif path_url.startswith("/_webhdf"): req.path_info = path_url[len("/_webhdf"):]
def front_end(self): """ All of the single-page application assets are delivered using WebOb's DirectoryApp. """ return DirectoryApp(static_dir)
def __init__(self, req, link, data, **config): super(exctrl, self).__init__(req, link, data, **config) self.static_app = DirectoryApp('%s/html/' % PATH) self.exapp = data[ex_instance_name]