GithubHelp home page GithubHelp logo

tako's Introduction

tako -- Functional web framework.

Install

  npm install tako

Add Sockets

  npm install socket.io

Or from source:

  git clone git://github.com/mikeal/tako.git 
  cd tako
  npm link

Usage

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('<html><head>cool</head><body>'+r.body.index+'</body></html>')
    })
  })
  .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

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)

tako's People

Contributors

adamghill avatar alexindigo avatar isaacs avatar max-mapper avatar mikeal avatar mmalecki avatar saambarati avatar shuhblam avatar soldair avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.