2015-05-13 5 views
0

Я пишу веб-сервер vertx.io и пытаюсь создать простой веб-ответ, состоящий из веб-страницы. Мне удалось отправить index.html, который отображается. Как добавить дополнительные файлы, такие как файлы JavaScript и CSS, чтобы можно было отобразить полную веб-страницу? Или, желательно, отправьте файлы один раз, так как они не изменятся.Vertx: Как добавить дополнительные файлы

RouteMatcher routeMatcher = new RouteMatcher().get("/", new Handler<HttpServerRequest>() { 
    @Override 
    public void handle(HttpServerRequest httpServerRequest) { 
     httpServerRequest.response().sendFile("src/web/index.html"); 
    } 
}); 

vertx.createHttpServer().requestHandler(routeMatcher).listen(8181, "localhost"); 

ответ

0
RouteMatcher httpRouteMatcher = new RouteMatcher().get("/", new 
Handler<HttpServerRequest>() { 
    @Override 
    public void handle(final HttpServerRequest request) { 
     request.response().sendFile("web/chat.html"); 
    } 
}).get(".*\\.(css|js)$", new Handler<HttpServerRequest>() { 
    @Override 
    public void handle(final HttpServerRequest request) { 
     request.response().sendFile("web/" + new File(request.path())); 
    } 
}); 
Смежные вопросы