2017-04-21 1 views
1

Je suis nouveau sur vertx-web. Je construis une application web en utilisant ruby ​​vertx-web. Je voudrais servir le fichier statique (index.html). et Mon index.html emballé dans le dossier webroot. Mon fichier index.html va charger pour http://localhost:8088. J'ai besoin de servir index.html pour localhost: 8088/demo OU localhost: 8088/test OU http://localhost:8088/ * (* pourrait être n'importe quoi et devrait servir index.html).Vertx web Routing

structure de répertoire:

  • frontend

    • Webroot

      • index.html
      • index.css
    • sever.rb

Toute aide sera appréciée.

Répondre

0

Essayez ceci:

router.route("/static/*").handler(&VertxWeb::StaticHandler.create().setWebRoot("webroot").method(:handle)) 
+0

Salut niraj, router.route_with_regex (". */Index.html"). Handler() {| ctx | réponse = ctx.response() response.put_header ("type de contenu", "text/html") response.set_chunked (true) response.send_file ("Webroot/index.html") } et il charge index.html mais il ne chargera pas les fichiers css et js ceux contenus dans index.html –

0

Vous pouvez définir une route par défaut en dernier itinéraire et définir un gestionnaire qui envoie uniquement le fichier index.html:

router.route().handler(rc -> { 
    rc.response().sendFile("webroot/index.html"); 
}); 

Ceci est la version Java, mais la traduction à Ruby devrait être facile.

0

le code suivant fonctionne pour moi.

router.route_with_regex(".*/index.html").handler() { |routingContext| router.route().handler(&VertxWeb::StaticHandler.create().method(:handle)) 

    response = routingContext.response() 

    response.put_header("content-type", "text/html") 
    response.set_chunked(true) 

    response.send_file("webroot/index.html") 

}