Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bricks

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bricks - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

logs/access.log

13

CHANGELOG.md
## Changes
### 1.1.1 - December 4, 2011
* `plugin.meta` added to plugin definition
* `author` - author name
* `email` - author email
* `name` - plugin name
* `description` - plugin description
* `plugin.name` deprecated in favor of `plugin.meta.name`
* added `html` and `callback` to `404 handler`
* added headers, expiration, and modification checks to `filehandler plugin`
* added `options.timeout` for cache headers
* added `304` response for `If-Modified-Since` headers
### 1.1.0 - November 27, 2011

@@ -4,0 +17,0 @@

9

lib/appserver.js

@@ -49,2 +49,3 @@ (function () {

options.path = path;

@@ -55,5 +56,11 @@ if (typeof(call) === 'function') {

if (call.name !== undefined) {
options.routeName = call.name;
console.warn('plugin.name has been deprecated in favor of plugin.meta.name');
options.routeName = (call.meta && call.meta.name ? call.meta.name : call.name);
} else if (call.meta && call.meta.name) {
options.routeName = call.meta.name;
}
options.meta = call.meta;
if (call.init !== undefined) {

@@ -60,0 +67,0 @@ options.appServer = this;

(function () {
exports.plugin = function (request, response, options) {
response.statusCode(404);
response.write('404 Error');
options = options || { };
options.statusCode = options.statusCode || 404;
response.statusCode(options.statusCode);
if (options.html !== undefined) {
response.write(options.html);
} else {
response.write('404 Error');
}
if (options.callback !== undefined && typeof (options.callback) === 'function') {
options.callback(request);
}
response.end();
};
exports.name = 'default 404 handler';
exports.meta = {
name: '404 handler',
description: 'Default 404 plugin'
};
})();

5

lib/plugins/clfloghandler.js

@@ -29,3 +29,6 @@ (function () {

exports.name = 'default logger';
exports.meta = {
name: 'logger',
description: 'Default CLF logger plugin'
};
})();

@@ -1,2 +0,2 @@

(function () {
(function() {
var fs = require('fs'),

@@ -7,35 +7,63 @@ path = require('path'),

require('date-utils');
var base;
exports.name = 'default file handler';
exports.init = function (options) {
options = options || { };
base = options.basedir || '.';
exports.meta = {
name: 'default file handler',
description: 'Basic file handler plugin'
};
exports.plugin = function (request, response, options) {
var parsed = url.parse(request.url, true);
exports.init = function(options) {
options = options || {};
base = options.basedir || '.';
};
exports.plugin = function(request, response, options) {
var parsed = url.parse(request.url, true);
var pathname = path.normalize(parsed.pathname);
var file = base + '/' + pathname;
fs.stat(file, function (err, stats) {
if (err !== null) {
response.next();
} else {
fs.readFile(file, "binary", function (err, data) {
if (err !== null) {
response.next();
} else {
response.setHeader('Content-Type', mime.lookup(file));
response.write(data);
fs.stat(file,
function(err, stats) {
if (err !== null) {
response.next();
} else {
if (request.headers['if-modified-since']) {
var modified = Date.parse(request.headers['if-modified-since']);
response.end();
if (modified && modified <= stats.mtime.valueOf()) {
response.statusCode(304);
response.end();
return;
}
}
});
fs.readFile(file, "binary",
function(err, data) {
if (err !== null) {
response.next();
} else {
response.setHeader('Content-Type', mime.lookup(file));
response.setHeader('Date', new Date().toUTCString());
response.setHeader('Last-Modified', stats.mtime.toUTCString());
response.setHeader('Age', parseInt((new Date().valueOf() - stats.mtime.valueOf()) / 1000));
if (options.timeout) {
response.setHeader('Cache-Control', 'max-age=' + options.timeout + ', public');
response.setHeader('Expires', stats.mtime.clone().add({ seconds: options.timeout }).toUTCString());
}
response.write(data);
response.end();
}
}
);
}
}
});
);
};
})();
})();

@@ -6,4 +6,7 @@ (function () {

exports.name = 'default redirect handler';
exports.meta = {
name: 'redirect handler',
description: 'Default redirect plugin'
};
exports.init = function (options) {

@@ -10,0 +13,0 @@ routes = options.routes;

@@ -5,2 +5,7 @@ (function () {

exports.meta = {
name: 'request handler',
description: 'Naive request augmentation plugin'
};
exports.plugin = function (request, response, options) {

@@ -7,0 +12,0 @@ var parsed = url.parse(request.url, true);

@@ -6,3 +6,6 @@ (function () {

exports.name = 'default session handler';
exports.meta = {
name: 'session handler',
description: 'Default session handler plugin'
};

@@ -9,0 +12,0 @@ exports.plugin = function (request, response, options) {

@@ -5,3 +5,3 @@ {

"description": "Bricks Application Server",
"version": "1.1.0",
"version": "1.1.1",
"homepage": "http://bricksjs.com/",

@@ -8,0 +8,0 @@ "preferGlobal": "true",

@@ -5,3 +5,4 @@ var vows = require('vows'),

mrequest = require('./mocks/request'),
mresponse = require('./mocks/response');
mresponse = require('./mocks/response'),
fs = require('fs');

@@ -125,3 +126,24 @@ vows.describe('Plugins').addBatch({

}
},
'filehandler sets correct Last-Modified header': {
topic: function () {
var appserver = new server.appserver();
var thisp = this;
appserver.addRoute(".+", appserver.plugins.filehandler, { basedir: __dirname });
appserver.addRoute(".+", function (request, response, options) {
thisp.callback(undefined, request, response, options);
}, { section: "final" });
var req = new mrequest.request();
req.url = "/document";
var res = new mresponse.response();
appserver.handleRequest(req, res, appserver);
},
'date is set correctly': function (err, request, response, options) {
var stats = fs.statSync(__dirname + "/document");
assert.equal(response._headers['Last-Modified'], stats.mtime.toUTCString());
}
}
}).export(module);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc