mirror of https://github.com/mthenw/frontail.git
Missing lint
parent
a6fe17462f
commit
f92de2f7c2
4
index.js
4
index.js
|
@ -81,10 +81,10 @@ var connectBuilder = require('./lib/connect_builder');
|
|||
|
||||
if (doAuthorization) {
|
||||
builder.session(sessionSecret, sessionKey);
|
||||
builder.authorize(program.user, program.password)
|
||||
builder.authorize(program.user, program.password);
|
||||
}
|
||||
|
||||
builder.static(__dirname + '/lib/web/assets')
|
||||
builder.static(__dirname + '/lib/web/assets');
|
||||
|
||||
var app = builder.build().use(function (req, res) {
|
||||
fs.readFile(__dirname + '/lib/web/index.html', function (err, data) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var connect = require('connect');
|
||||
|
||||
(function() {
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var ConnectBuilder = function () {
|
||||
|
@ -20,17 +20,17 @@ var connect = require('connect');
|
|||
};
|
||||
|
||||
ConnectBuilder.prototype.session = function (secret, key) {
|
||||
this.app.use(connect.cookieParser())
|
||||
this.app.use(connect.session({secret: secret, key: key}))
|
||||
this.app.use(connect.cookieParser());
|
||||
this.app.use(connect.session({secret: secret, key: key}));
|
||||
return this;
|
||||
};
|
||||
|
||||
ConnectBuilder.prototype.static = function (path) {
|
||||
this.app.use(connect.static(path));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function () {
|
||||
return new ConnectBuilder();
|
||||
}
|
||||
};
|
||||
})();
|
|
@ -1,5 +1,4 @@
|
|||
var connectBuilder = require('../lib/connect_builder');
|
||||
var connect = require('connect');
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
@ -50,7 +49,7 @@ var connect = require('connect');
|
|||
.request()
|
||||
.get('/')
|
||||
.end(function (res) {
|
||||
res.headers['set-cookie'][0].should.startWith('sessionkey')
|
||||
res.headers['set-cookie'][0].should.startWith('sessionkey');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,116 +1,119 @@
|
|||
var EventEmitter = require('events').EventEmitter;
|
||||
var methods = ['get', 'post', 'put', 'delete', 'head'];
|
||||
var connect = require('connect');
|
||||
var http = require('http');
|
||||
var util = require('util');
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
, methods = ['get', 'post', 'put', 'delete', 'head']
|
||||
, connect = require('connect')
|
||||
, http = require('http');
|
||||
|
||||
module.exports = request;
|
||||
|
||||
connect.proto.request = function(){
|
||||
return request(this);
|
||||
};
|
||||
|
||||
function request(app) {
|
||||
return new Request(app);
|
||||
}
|
||||
|
||||
function Request(app) {
|
||||
var self = this;
|
||||
this.data = [];
|
||||
this.header = {};
|
||||
this.app = app;
|
||||
if (!this.server) {
|
||||
this.server = http.Server(app);
|
||||
this.server.listen(0, '127.0.0.1', function(){
|
||||
self.addr = self.server.address();
|
||||
self.listening = true;
|
||||
});
|
||||
function request(app) {
|
||||
return new Request(app);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `EventEmitter.prototype`.
|
||||
*/
|
||||
module.exports = request;
|
||||
|
||||
Request.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
methods.forEach(function(method){
|
||||
Request.prototype[method] = function(path){
|
||||
return this.request(method, path);
|
||||
connect.proto.request = function () {
|
||||
return request(this);
|
||||
};
|
||||
});
|
||||
|
||||
Request.prototype.set = function(field, val){
|
||||
this.header[field] = val;
|
||||
return this;
|
||||
};
|
||||
function Request(app) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
Request.prototype.write = function(data){
|
||||
this.data.push(data);
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.request = function(method, path){
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.expect = function(body, fn){
|
||||
var args = arguments;
|
||||
this.end(function(res){
|
||||
switch (args.length) {
|
||||
case 3:
|
||||
res.headers.should.have.property(body.toLowerCase(), args[1]);
|
||||
args[2]();
|
||||
break;
|
||||
default:
|
||||
if ('number' == typeof body) {
|
||||
res.statusCode.should.equal(body);
|
||||
} else {
|
||||
res.body.should.equal(body);
|
||||
}
|
||||
fn();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Request.prototype.end = function(fn){
|
||||
var self = this;
|
||||
|
||||
if (this.listening) {
|
||||
var req = http.request({
|
||||
method: this.method
|
||||
, port: this.addr.port
|
||||
, host: this.addr.address
|
||||
, path: this.path
|
||||
, headers: this.header
|
||||
});
|
||||
|
||||
this.data.forEach(function(chunk){
|
||||
req.write(chunk);
|
||||
});
|
||||
|
||||
req.on('response', function(res){
|
||||
var buf = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function(chunk){ buf += chunk });
|
||||
res.on('end', function(){
|
||||
res.body = buf;
|
||||
fn(res);
|
||||
var self = this;
|
||||
this.data = [];
|
||||
this.header = {};
|
||||
this.app = app;
|
||||
if (!this.server) {
|
||||
this.server = http.Server(app);
|
||||
this.server.listen(0, '127.0.0.1', function () {
|
||||
self.addr = self.server.address();
|
||||
self.listening = true;
|
||||
});
|
||||
});
|
||||
|
||||
req.end();
|
||||
} else {
|
||||
this.server.on('listening', function(){
|
||||
self.end(fn);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Inherit from `EventEmitter.prototype`.
|
||||
*/
|
||||
|
||||
util.inherits(Request, EventEmitter);
|
||||
|
||||
methods.forEach(function (method) {
|
||||
Request.prototype[method] = function (path) {
|
||||
return this.request(method, path);
|
||||
};
|
||||
});
|
||||
|
||||
Request.prototype.set = function (field, val) {
|
||||
this.header[field] = val;
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.write = function (data) {
|
||||
this.data.push(data);
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.request = function (method, path) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.expect = function (body, fn) {
|
||||
var args = arguments;
|
||||
this.end(function (res) {
|
||||
switch (args.length) {
|
||||
case 3:
|
||||
res.headers.should.have.property(body.toLowerCase(), args[1]);
|
||||
args[2]();
|
||||
break;
|
||||
default:
|
||||
if ('number' === typeof body) {
|
||||
res.statusCode.should.equal(body);
|
||||
} else {
|
||||
res.body.should.equal(body);
|
||||
}
|
||||
fn();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Request.prototype.end = function (fn) {
|
||||
var self = this;
|
||||
|
||||
if (this.listening) {
|
||||
var req = http.request({
|
||||
method: this.method,
|
||||
port: this.addr.port,
|
||||
host: this.addr.address,
|
||||
path: this.path,
|
||||
headers: this.header
|
||||
});
|
||||
|
||||
this.data.forEach(function (chunk) {
|
||||
req.write(chunk);
|
||||
});
|
||||
|
||||
req.on('response', function (res) {
|
||||
var buf = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function (chunk) { buf += chunk; });
|
||||
res.on('end', function () {
|
||||
res.body = buf;
|
||||
fn(res);
|
||||
});
|
||||
});
|
||||
|
||||
req.end();
|
||||
} else {
|
||||
this.server.on('listening', function () {
|
||||
self.end(fn);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in New Issue