Created
February 19, 2012 10:39
-
-
Save diosmosis/1863101 to your computer and use it in GitHub Desktop.
Example snippets that use thewire
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
thewire = require 'thewire' | |
Layout = (data, more_data, body) -> | |
# ... | |
View1 = (pages) -> | |
# ... | |
View2 = (page) -> | |
# ... | |
exports.controller = thewire.controller 'the-url-root', | |
layout: | |
view: Layout | |
model: ['/route/to/data', '/route/to/more/data'] | |
routes: | |
'/go/to/pages': | |
view: View1 | |
model: '/route/to/data' | |
'/go/to/specific/:page': | |
view: View2 | |
model: (url) -> '/route/to/pages/' + url.page | |
expects_one: true |
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
thewire = require 'thewire' | |
class MyService extends thewire.node.Service | |
constructor: (name, url_root, details) -> | |
super(name, url_root, details) | |
'GET:/some/random/route': (ctx, callback) -> | |
somearg = ctx.parsed_url.args.somearg | |
if somearg | |
# send a success message | |
callback(null, {success: true, message: "You set somearg=#{ somearg }!"}) | |
else | |
# send back error | |
callback(new Error("The somearg query parameter must be present!")) | |
'POST:/to/:here': (ctx, callback) -> | |
# write some HTML back | |
callback( | |
null, | |
"<p>The second part of this request's URL is '#{ ctx.parsed_url.here }'.</p>", | |
{format: 'html'}) | |
exports.service = MyService |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment