var formulator = require ('../src/formulator'),
  fs = require('fs'),
  http = require('http');

var addUser = new formulator(
  require('./formulas/forms/user.json')
);

http.createServer(function (req, res) {
  switch (true) {
    case req.url.match(/^\/formulas/) !== null:
      res.end(fs.readFileSync('example' + req.url, 'utf8'));
      break;
    case req.url == '/formulator.js':
      res.end(fs.readFileSync('src/formulator.js', 'utf8'));
      break;
    case req.url == '/html':
      res.end('<!DOCTYPE html><a href="..">Back</a>' + addUser.toString());
      break;
    case req.url == '/js':
      res.end(fs.readFileSync('example/views/js.html', 'utf8'));
      break;
    case req.url == '/js-remote':
      res.end(fs.readFileSync('example/views/js-remote.html', 'utf8'));
      break;
    default:
      res.end(fs.readFileSync('example/client.html', 'utf8'));
      break;
  }
}).listen(10101);

console.log('Formulator started on http://127.0.0.1:10101');