Last active
August 29, 2015 14:01
-
-
Save aaronpowell/b7ab563ea8dac06a7d8c to your computer and use it in GitHub Desktop.
Express.js + Sweet.js + modules
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
var express = require('express'); | |
var app = express(); | |
get '/404' send(404) 'Not Found' | |
get '/foo' with (req, res) { | |
res.json({ foo: 'bar' }); | |
} | |
get '/' send 'Hello World' | |
app.listen(3000); |
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
macro copy_context { | |
case { _ ($from, $to) } => { | |
return [makeIdent(unwrapSyntax(#{ $to }), #{ $from })]; | |
} | |
} | |
macroclass status { | |
pattern { $method:ident($code:lit) } | |
} | |
let get = macro { | |
case { $m $path:lit $do $res:lit } => { | |
return #{ | |
copy_context($m, app).get($path, function (req, res) { | |
res.$do($res); | |
}); | |
} | |
} | |
case { $m $path:lit $what:status $res:lit } => { | |
return #{ | |
copy_context($m, app).get($path, function (req, res) { | |
res.$what$method($what$code, $res); | |
}); | |
} | |
} | |
case { $m $path:lit with ($req:ident, $res:ident) { $body ... } } => { | |
return #{ | |
copy_context($m, app).get($path, function ($req, $res) { | |
$body ... | |
}); | |
} | |
} | |
} | |
export get |
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
{ | |
"name": "sweetjs-express", | |
"version": "0.0.0", | |
"description": "", | |
"main": "app.js", | |
"dependencies": { | |
"express": "^4.2.0", | |
"sweet.js": "^0.6.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Aaron Powell", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment