forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
2,799 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
apex-examples/src/main/groovy/io/vertx/example/apex/auth/private/private_page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<html> | ||
|
||
<head> | ||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/> | ||
<meta http-equiv="Pragma" content="no-cache"/> | ||
<meta http-equiv="Expires" content="0"/> | ||
</head> | ||
|
||
<body> | ||
|
||
<h2>You can only see this page if you are logged in!</h2> | ||
|
||
<br> | ||
<br> | ||
<a href="/logout">Logout</a> | ||
|
||
</body> | ||
|
||
</html> |
40 changes: 40 additions & 0 deletions
40
apex-examples/src/main/groovy/io/vertx/example/apex/auth/server.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import io.vertx.groovy.ext.apex.Router | ||
import io.vertx.groovy.ext.apex.handler.CookieHandler | ||
import io.vertx.groovy.ext.apex.handler.SessionHandler | ||
import io.vertx.groovy.ext.apex.sstore.LocalSessionStore | ||
import io.vertx.groovy.ext.apex.handler.BodyHandler | ||
import io.vertx.groovy.ext.auth.shiro.ShiroAuthService | ||
import io.vertx.groovy.ext.apex.handler.RedirectAuthHandler | ||
import io.vertx.groovy.ext.apex.handler.StaticHandler | ||
import io.vertx.groovy.ext.apex.handler.FormLoginHandler | ||
|
||
def router = Router.router(vertx) | ||
|
||
// We need cookies, sessions and request bodies | ||
router.route().handler(CookieHandler.create()) | ||
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))) | ||
router.route().handler(BodyHandler.create()) | ||
|
||
// Simple auth service which uses a properties file for user/role info | ||
def authService = ShiroAuthService.create(vertx, 'PROPERTIES', [:]) | ||
|
||
// Any requests to URI starting '/private/' require login | ||
router.route("/private/*").handler(RedirectAuthHandler.create(authService, "/loginpage.html")) | ||
|
||
// Serve the static private pages from directory 'private' | ||
router.route("/private/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("private")) | ||
|
||
// Handles the actual login | ||
router.route("/loginhandler").handler(FormLoginHandler.create(authService)) | ||
|
||
// Implement logout | ||
router.route("/logout").handler({ context -> | ||
context.session().logout() | ||
// Redirect back to the index page | ||
context.response().putHeader("location", "/").setStatusCode(302).end() | ||
}) | ||
|
||
// Serve the non private static pages | ||
router.route().handler(StaticHandler.create()) | ||
|
||
vertx.createHttpServer().requestHandler(router.&accept).listen(8080) |
15 changes: 15 additions & 0 deletions
15
apex-examples/src/main/groovy/io/vertx/example/apex/auth/webroot/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
|
||
<body> | ||
|
||
<h1>Web site with public and private pages</h1> | ||
|
||
<br> | ||
<br> | ||
<a href="private/private_page.html">Private page - login is required</a> | ||
|
||
<br><br> | ||
|
||
<a href="page1.html">Public page - no login required</a> | ||
</body> | ||
</html> |
29 changes: 29 additions & 0 deletions
29
apex-examples/src/main/groovy/io/vertx/example/apex/auth/webroot/loginpage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/> | ||
<meta http-equiv="Pragma" content="no-cache"/> | ||
<meta http-equiv="Expires" content="0"/> | ||
</head> | ||
<body> | ||
<h2>Please login</h2><br> | ||
|
||
<br> | ||
(Username is 'tim', password is 'sausages') | ||
<br> | ||
<br> | ||
|
||
<form action="/loginhandler" method="post"> | ||
<div> | ||
<label>Username:</label> | ||
<input type="text" name="username"/> | ||
</div> | ||
<div> | ||
<label>Password:</label> | ||
<input type="password" name="password"/> | ||
</div> | ||
<div> | ||
<input type="submit" value="Log In"/> | ||
</div> | ||
</form> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
apex-examples/src/main/groovy/io/vertx/example/apex/auth/webroot/page1.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>Welcome to page1!</h1> | ||
|
||
<br> | ||
This page does not require login - anyone can see it | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
apex-examples/src/main/groovy/io/vertx/example/apex/helloworld/server.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import io.vertx.groovy.ext.apex.Router | ||
|
||
def router = Router.router(vertx) | ||
|
||
router.route().handler({ routingContext -> | ||
routingContext.response().putHeader("content-type", "text/html").end("Hello World!") | ||
}) | ||
|
||
vertx.createHttpServer().requestHandler(router.&accept).listen(8080) |
26 changes: 26 additions & 0 deletions
26
apex-examples/src/main/groovy/io/vertx/example/apex/realtime/server.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import io.vertx.groovy.ext.apex.Router | ||
import io.vertx.groovy.ext.apex.handler.sockjs.SockJSHandler | ||
import io.vertx.groovy.ext.apex.handler.StaticHandler | ||
|
||
def router = Router.router(vertx) | ||
|
||
// Allow outbound traffic to the news-feed address | ||
|
||
def options = [ | ||
outboundPermitteds:[ | ||
[ | ||
address:"news-feed" | ||
] | ||
] | ||
] | ||
|
||
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options)) | ||
|
||
// Serve the static resources | ||
router.route().handler(StaticHandler.create()) | ||
|
||
vertx.createHttpServer().requestHandler(router.&accept).listen(8080) | ||
|
||
// Publish a message to the address "news-feed" every second | ||
vertx.setPeriodic(1000, { t -> | ||
vertx.eventBus().publish("news-feed", "news from the server!")}) |
35 changes: 35 additions & 0 deletions
35
apex-examples/src/main/groovy/io/vertx/example/apex/realtime/webroot/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<html> | ||
<head> | ||
<title></title> | ||
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script> | ||
<script src="vertxbus.js"></script> | ||
</head> | ||
|
||
<style> | ||
.news { | ||
font-size: 20pt; | ||
} | ||
</style> | ||
|
||
<body> | ||
|
||
<div class="news">Latest news: </div><br> | ||
<div id="status" class="news"></div> | ||
|
||
<script> | ||
|
||
var eb = new vertx.EventBus("http://localhost:8080/eventbus"); | ||
|
||
eb.onopen = function() { | ||
eb.registerHandler("news-feed", function(msg) { | ||
var str = "<code>" + msg + "</code><br>"; | ||
$('#status').prepend(str); | ||
}) | ||
} | ||
|
||
|
||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.