Vertx:如何包含其他文件

时间:2022-06-13 18:07:13

I am writing a vertx.io web server and am trying to create a simple web reponse, consisting of a web page. I have managed to send index.html, which is displayed. How do I add additional files, such as JavaScript and CSS files, so that a full webpage can be displayed? Or preferably, send the files once, since they will not change.

我正在写一个vertx.io网络服务器,我正在尝试创建一个简单的网络响应,包括一个网页。我已设法发送index.html,显示。如何添加其他文件,例如JavaScript和CSS文件,以便显示完整的网页?或者最好发送一次文件,因为它们不会改变。

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");

1 个解决方案

#1


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()));
    }
});

#1


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()));
    }
});