Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikeal/tako
Functional web framework.
https://github.com/mikeal/tako
Last synced: 9 days ago
JSON representation
Functional web framework.
- Host: GitHub
- URL: https://github.com/mikeal/tako
- Owner: mikeal
- Created: 2012-02-27T21:07:51.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T22:04:36.000Z (over 7 years ago)
- Last Synced: 2024-05-01T22:25:48.729Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 320
- Watchers: 10
- Forks: 17
- Open Issues: 14
-
Metadata Files:
- Readme: README.mkd
Awesome Lists containing this project
- awesome-github-repos - mikeal/tako - Functional web framework. (JavaScript)
- awesome-starred - mikeal/tako - Functional web framework. (others)
README
# tako -- Functional web framework.
## Install
npm install tako## Add Sockets
npm install socket.ioOr from source:
git clone git://github.com/mikeal/tako.git
cd tako
npm link## Usage
```javascript
var tako = require('tako')
, request = require('request')
, path = require('path')
, app = tako()
;app.route('/static/*').files(path.join(__dirname, 'static'))
app.route('/proxypass', function (req, resp) {
req.pipe(request("http://otherserver.com"+req.url).pipe(resp))
})app.route('/hello.json').json({msg:'hello!'})
app.route('/plaintext').text('I like text/plain')
app.route('/')
.html(function (req, resp) {
request('http://me.iriscouch.com/db', {json:true}, function (e, r) {
if (e) return resp.error(e)
if (r.statusCode !== 200) return resp.error(r)
resp.end('cool'+r.body.index+'')
})
})
.methods('GET')
;// Ported example from socket.io docs to show integration
app.sockets.on('connection', function (socket) {
app.sockets.emit('news', { will: 'be received by everyone'});
socket.on('disconnect', function () {
app.sockets.emit('user disconnected')
})
})
app.httpServer.listen(80)
app.httpsServer.listen(443)
```### Routing multiple domains
```javascript
var tako = require('../index')
, app1 = tako()
, app2 = tako()
, default = tako()
, router = tako.router()
;
app1.route('/name').text('app1')
app2.route('/name').text('app2')
default.route('/name').text('default')router.host('app1.localhost', app1)
router.host('app2.localhost', app2)
router.default(default)router.httpServer.listen(80)
router.httpsServer.listen(443)
```