diff --git a/app.js b/app.js new file mode 100644 index 0000000..18e49b8 --- /dev/null +++ b/app.js @@ -0,0 +1,23 @@ +'use strict'; + +var http = require('http'); +var nodeStatic = require('node-static'); + +var staticServer = new nodeStatic.Server('./static'); +var app = http.createServer(function(req, res, next) { + // serve index for all app pages + if (req.url.indexOf('/builds') === 0) { + staticServer.serveFile('/index.html', 200, {}, req, res); + } else { + if (req.url.indexOf('/data.io.js') === -1) { + staticServer.serve(req, res); + } + } +}); + +var io = require('socket.io')(app); +var data = require('data.io')(io); + +require('./resources')(data); + +app.listen(3000); diff --git a/package.json b/package.json index fb3833a..e131729 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,16 @@ }, "homepage": "https://github.com/okv/nci", "dependencies": { + "data.io": "^0.3.0", + "node-static": "^0.7.6", + "socket.io": "^1.3.5", "twostep": "0.4.1", "underscore": "1.8.2" }, "devDependencies": { + "bower": "^1.4.1", "expect.js": "0.3.1", - "mocha": "1.18.2" + "mocha": "1.18.2", + "nodemon": "^1.3.7" } } diff --git a/resources/builds.js b/resources/builds.js new file mode 100644 index 0000000..9fa8e03 --- /dev/null +++ b/resources/builds.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = function(data) { + var builds = [{ + project: { + name: 'foo' + }, + start: Date.now(), + step: 1, + completed: false, + status: 'inprogress' + }]; + + var resource = data.resource('builds'); + + resource.use('readAll', function(req, res) { + console.log('readAll'); + res.send(builds); + }); +}; diff --git a/resources/index.js b/resources/index.js new file mode 100644 index 0000000..332f4eb --- /dev/null +++ b/resources/index.js @@ -0,0 +1,9 @@ +'use strict'; + +var _ = require('underscore'); + +module.exports = function(data) { + _(['builds', 'projects']).each(function(resource) { + require('./' + resource)(data); + }); +}; diff --git a/resources/projects.js b/resources/projects.js new file mode 100644 index 0000000..ebe3e24 --- /dev/null +++ b/resources/projects.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = function(data) { + var projects = [{ + name: 'foo' + }]; +}; diff --git a/static/app.js b/static/app.js new file mode 100644 index 0000000..3f0203e --- /dev/null +++ b/static/app.js @@ -0,0 +1,10 @@ +'use strict'; + +var conn = data(io.connect()); +var builds = conn.resource('builds'); + +console.log(builds); + +builds.sync('readAll', function(err, result) { + console.log(result); +}); diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..36c1e4c --- /dev/null +++ b/static/index.html @@ -0,0 +1,20 @@ + + +
+ + + + + + + +