Skip to content

Commit

Permalink
add middleware example
Browse files Browse the repository at this point in the history
  • Loading branch information
cmather committed Jul 21, 2014
1 parent 78f910c commit 9e06c3c
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/middleware/.meteor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
1 change: 1 addition & 0 deletions examples/middleware/.meteor/identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
121o36bh27c5ejtr3g0
10 changes: 10 additions & 0 deletions examples/middleware/.meteor/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

standard-app-packages
autopublish
insecure
iron:router

1 change: 1 addition & 0 deletions examples/middleware/.meteor/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
none
1 change: 1 addition & 0 deletions examples/middleware/middleware.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* CSS declarations go here */
20 changes: 20 additions & 0 deletions examples/middleware/middleware.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<head>
<title>middleware</title>
</head>

<body>
</body>

<template name="Home">
<h1>Home Page</h1>

<p>
Check out the JavaScript console
</p>
</template>

<template name="NoRouteFound">
<h1>
Sorry, no route was found for "{{url}}" on the client or the server!
</h1>
</template>
26 changes: 26 additions & 0 deletions examples/middleware/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// middleware on the server which uses the same api as Connect
// middleware
Router.use(function (req, res, next) {
// we use the connect middleware req, res objects here
console.log(req.method + ": " + req.url);
next();

// or, the request, response and next functions are also
// attached to "this": this.request, this.response, this.next()
}, {where: 'server'});

Router.route('/file', function () {
this.response.end("here's your file...\n");
}, {where: 'server'});


// middlware on the client
Router.use(function () {
console.log('Middleware on the client with url: ', this.url);
this.next();
});

Router.route('/', function () {
this.render('Home');
});

0 comments on commit 9e06c3c

Please sign in to comment.