Java Code Examples for io.vertx.ext.web.handler.StaticHandler#create()

The following examples show how to use io.vertx.ext.web.handler.StaticHandler#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainModule.java    From cassandra-sidecar with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public Router vertxRouter(Vertx vertx)
{
    Router router = Router.router(vertx);
    router.route().handler(LoggerHandler.create());

    // Static web assets for Swagger
    StaticHandler swaggerStatic = StaticHandler.create("META-INF/resources/webjars/swagger-ui");
    router.route().path("/static/swagger-ui/*").handler(swaggerStatic);

    // Docs index.html page
    StaticHandler docs = StaticHandler.create("docs");
    router.route().path("/docs/*").handler(docs);

    return router;
}
 
Example 2
Source File: VertxNubes.java    From nubes with Apache License 2.0 6 votes vote down vote up
private void setUpRouter(Router paramRouter) {
  router = paramRouter;
  router.route().failureHandler(failureHandler);
  if (locResolver != null) {
    locResolver.getAvailableLocales().forEach(this::loadResourceBundle);
    if (locResolver.getDefaultLocale() != null) {
      loadResourceBundle(locResolver.getDefaultLocale());
    }
  }
  if (config.getAuthProvider() != null) {
    registerAnnotationProcessor(Auth.class, new AuthProcessorFactory());
  }
  new RouteFactory(router, config).createHandlers();
  new SocketFactory(router, config).createHandlers();
  new EventBusBridgeFactory(router, config).createHandlers();
  StaticHandler staticHandler;
  final String webroot = config.getWebroot();
  if (webroot != null) {
    staticHandler = StaticHandler.create(webroot);
  } else {
    staticHandler = StaticHandler.create();
  }
  router.route(config.getAssetsPath() + "/*").handler(staticHandler);
}
 
Example 3
Source File: StaticWebpageDispatcher.java    From servicecomb-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Router router) {
  String regex = "/(.*)";
  StaticHandler webpageHandler = StaticHandler.create();
  webpageHandler.setWebRoot(WEB_ROOT);
  LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
  router.routeWithRegex(regex).failureHandler((context) -> {
    LOGGER.error("", context.failure());
  }).handler(webpageHandler);
}
 
Example 4
Source File: StaticWebpageDispatcher.java    From servicecomb-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Router router) {
  String regex = "/ui/(.*)";
  StaticHandler webpageHandler = StaticHandler.create();
  webpageHandler.setWebRoot(WEB_ROOT);
  LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
  router.routeWithRegex(regex).failureHandler((context) -> {
    LOGGER.error("", context.failure());
  }).handler(webpageHandler);
}
 
Example 5
Source File: StaticWebpageDispatcher.java    From servicecomb-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Router router) {
  String regex = "/ui/(.*)";
  StaticHandler webpageHandler = StaticHandler.create();
  webpageHandler.setWebRoot(WEB_ROOT);
  LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
  router.routeWithRegex(regex).failureHandler((context) -> {
    LOGGER.error("", context.failure());
  }).handler(webpageHandler);
}
 
Example 6
Source File: SwaggerUI.java    From simulacron with Apache License 2.0 5 votes vote down vote up
@Override
public void registerWithRouter(Router router) {
  StaticHandler staticHandler = StaticHandler.create();
  staticHandler.setWebRoot("META-INF/resources/webjars");
  router.route("/static/*").handler(staticHandler);

  // Disable caching so you don't need to clear cache everytime yaml changes.
  StaticHandler swaggerHandler =
      StaticHandler.create().setWebRoot("webroot/swagger").setCachingEnabled(false);
  router.route("/doc/*").handler(swaggerHandler);
}
 
Example 7
Source File: HttpServer.java    From Lealone-Plugins with Apache License 2.0 5 votes vote down vote up
private void setStaticHandler(Router router) {
    for (String root : webRoot.split(",", -1)) {
        root = root.trim();
        if (root.isEmpty())
            continue;
        StaticHandler sh = StaticHandler.create(root);
        sh.setCachingEnabled(false);
        router.route("/*").handler(sh);
    }
}