Initial commit

This commit is contained in:
Rowan Manning
2013-09-13 16:49:19 +01:00
commit 433aecd972
10 changed files with 148 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
# Config files
config/development.json
config/production.json
# Generated npm files
node_modules
npm-debug.log

18
Makefile Normal file
View File

@@ -0,0 +1,18 @@
# Group targets
all: deps
# Install dependencies
deps:
@echo "Installing dependencies..."
@npm install
# Start the application
start:
@echo "Starting application..."
@NODE_ENV=production node .
# Start the application in development mode
start-dev:
@echo "Starting application (development mode)..."
@NODE_ENV=development ./node_modules/.bin/supervisor -q .

35
app.js Normal file
View File

@@ -0,0 +1,35 @@
'use strict';
var async = require('async');
var createClient = require('pa11y-webservice-client-node');
var EventEmitter = require('events').EventEmitter;
var express = require('express');
var http = require('http');
module.exports = initApp;
// Initialise the application
function initApp (config, callback) {
var app = new EventEmitter();
app.address = null;
app.express = express();
app.server = http.createServer(app.express);
app.webservice = createClient(config.webservice);
require('./route/index')(app);
require('./route/new')(app);
require('./route/task')(app);
app.express.use(function (err, req, res, next) {
app.emit('route-error', err);
res.send('Error');
});
app.server.listen(config.port, function (err) {
var address = app.server.address();
app.address = 'http://' + address.address + ':' + address.port;
callback(err, app);
});
}

View File

@@ -0,0 +1,4 @@
{
"webservice": "http://localhost:3000/",
"port": 4000
}

View File

@@ -0,0 +1,4 @@
{
"webservice": "http://localhost:3000/",
"port": 4000
}

19
index.js Normal file
View File

@@ -0,0 +1,19 @@
'use strict';
var chalk = require('chalk');
var config = require('./config/' + (process.env.NODE_ENV || 'development') + '.json');
require('./app')(config, function (err, app) {
console.log('');
console.log(chalk.underline.magenta('pa11y-web started'));
console.log(chalk.grey('mode: %s'), process.env.NODE_ENV);
console.log(chalk.grey('uri: %s'), app.address);
app.on('route-error', function (err) {
if (err.code === 'ECONNREFUSED') {
console.log(chalk.red('Error: could not connect to pa11y-webservice'))
}
});
});

20
package.json Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "pa11y-web",
"version": "0.0.0",
"private": true,
"engines": {
"node": ">=0.10"
},
"dependencies": {
"chalk": "~0.2",
"express": "~3.4",
"pa11y-webservice-client-node": "git+ssh://git@github.com:nature/pa11y-webservice-client-node.git#1.0.0-beta.1"
},
"devDependencies": {
"supervisor": "~0.5"
},
"scripts": {
"start": "node ."
}
}

15
route/index.js Normal file
View File

@@ -0,0 +1,15 @@
'use strict';
module.exports = route;
// Route definition
function route (app) {
app.express.get('/', function (req, res, next) {
app.webservice.tasks.get(function (err, tasks) {
if (err) {
return next(err);
}
res.send(tasks);
});
});
}

10
route/new.js Normal file
View File

@@ -0,0 +1,10 @@
'use strict';
module.exports = route;
// Route definition
function route (app) {
app.express.get('/new', function (req, res) {
res.send('Create a task');
});
}

15
route/task.js Normal file
View File

@@ -0,0 +1,15 @@
'use strict';
module.exports = route;
// Route definition
function route (app) {
app.express.get('/:id', function (req, res, next) {
app.webservice.task(req.params.id).get(function (err, task) {
if (err) {
return next();
}
res.send(task);
});
});
}