Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ybonnel/vertx-livereload

A simple livereload server for vertx application
https://github.com/ybonnel/vertx-livereload

Last synced: about 2 months ago
JSON representation

A simple livereload server for vertx application

Awesome Lists containing this project

README

        

# Vertx-livereload

A very simple helper to have a [livereload](http://livereload.com/) server on a vertx application for your static resources.

## Motivation

Refresh a web page can be so long :), so just save your js/css/html file and when you arrived in you browser the change is already there.

## Implementation

All samples are in kotlin, but it's very simple, so the conversion to java must be easy.

Image you avec some static resources :

```kotlin
get("/public/*").handler(
StaticHandler.create("src/main/resources/public")
.setCachingEnabled(false)
)
```

this is just the dev example, in real life you may have something like that :

```kotlin
if (getMode() == "dev") {
get("/public/*").handler(
StaticHandler.create("src/main/resources/public")
.setCachingEnabled(false)
)
} else {
get("/public/*").handler(StaticHandler.create("public"))
}
```

Why not just the "prod mode" code? Because I don't want to wait the compile process to have my update :)

So, as you guess, I have some static files in ```src/main/resources/public``` which are served for url ```/public/*```
Now to add my livereload, I just add this code to my verticle :

```kotlin
import fr.ybonnel.vertx.livereload.LiveReload

class MainVerticle: AbstractVerticle() {
private lateinit var liveReloadServer: LiveReload

override fun start(startFuture: Future) {
/* ... */
liveReloadServer = LiveReload(this.vertx, mapOf(
"src/main/resources/public/" to "/public/"
))
liveReloadServer?.start()?.setHandler(startFuture)
}

override fun stop(stopFuture: Future) {
/* ... */
liveReloadServer?.stop()?.setHandler(stopFuture)
}
}
```

## Demo

![Demo](https://github.com/ybonnel/vertx-livereload/raw/master/vertx-livereload.gif)

## How to install

The artifact is published to bintray : [bintray.com/ybonnel/maven/vertx-livereload](https://bintray.com/ybonnel/maven/vertx-livereload)