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

aldo

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aldo - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

38

lib/application.js

@@ -5,3 +5,4 @@ "use strict";

const util_1 = require("util");
const handlers_1 = require("./handlers");
const assert = require("assert");
const aldo_compose_1 = require("aldo-compose");
const context_1 = require("./context");

@@ -26,4 +27,5 @@ const createDebugger = require("debug");

for (let fn of fns) {
this._handlers.push(_ensureFunction(fn));
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`);
debug(`use handler: ${fn.name || '<anonymous>'}`);
this._handlers.push(fn);
}

@@ -39,4 +41,5 @@ return this;

for (let fn of fns) {
this._errorHandlers.push(_ensureFunction(fn));
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`);
debug(`use error handler: ${fn.name || '<anonymous>'}`);
this._errorHandlers.push(fn);
}

@@ -49,4 +52,4 @@ return this;

callback() {
var handleError = handlers_1.compose(this._errorHandlers.length > 0 ? this._errorHandlers : [_report]);
var dispatch = handlers_1.compose(this._handlers);
var handleError = aldo_compose_1.default(this._errorHandlers.length > 0 ? this._errorHandlers : [_report]);
var dispatch = aldo_compose_1.default(this._handlers);
return (req, res) => {

@@ -73,4 +76,5 @@ var ctx = this._context.from(req, res);

bind(prop, fn) {
this._context.bind(prop, _ensureFunction(fn));
assert(typeof fn === 'function', `Function expected but got ${typeof fn}.`);
debug(`set a private context attribute: ${prop}`);
this._context.bind(prop, fn);
return this;

@@ -85,4 +89,4 @@ }

set(prop, value) {
debug(`set a shared context attribute: ${prop}`);
this._context.set(prop, value);
debug(`set a shared context attribute: ${prop}`);
return this;

@@ -117,22 +121,12 @@ }

/**
* Ensure the given argument is a function
* Handle the error response
*
* @param arg
* @private
*/
function _ensureFunction(arg) {
if (typeof arg === 'function')
return arg;
throw new TypeError(`Function expected but got ${typeof arg}.`);
}
/**
* Send the error response
*
* @param error
* @param ctx
* @private
*/
function _report({ error, res }) {
function _report(error, { res }) {
console.error(error);
res.statusCode = error.status || 500;
res.end(error.message);
console.error(error);
res.end(error.expose ? error.message : 'Internal Server Error');
}

@@ -69,3 +69,2 @@ "use strict";

ctx.req = req;
ctx.params = {};
return ctx;

@@ -72,0 +71,0 @@ }

{
"name": "aldo",
"version": "0.3.0",
"version": "0.3.1",
"description": "Fast micro framework for Node.js 8+",

@@ -15,2 +15,5 @@ "main": "lib/index.js",

],
"engines": {
"node": ">=8.9"
},
"repository": {

@@ -41,4 +44,5 @@ "type": "git",

"dependencies": {
"aldo-compose": "^1.0.1",
"debug": "^3.1.0"
}
}
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