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

hapi

Package Overview
Dependencies
Maintainers
1
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

Makefile

21

lib/defaults.js

@@ -60,19 +60,8 @@ /*

uri: 'http://localhost:80',
// tls: {
//
// key: '',
// cert: ''
// },
host: { // Automatically set from 'uri'
domain: 'localhost',
scheme: 'http',
port: '80',
authority: 'localhost:80'
},
tls: {
isOn: false, // Automatically set when TLS is initialized
key: '',
cert: ''
},
// Terms of Service

@@ -79,0 +68,0 @@

@@ -9,3 +9,2 @@ /*

var Os = require('os');
var Sugar = require('sugar');
var Utils = require('./utils');

@@ -32,3 +31,3 @@ var Log = require('./log');

exports.settings = Object.merge(Defaults.process, options || {}); // Must happen first to populate configuration required by other modules
exports.settings = Utils.merge(Utils.clone(Defaults.process), options || {}); // Must happen first to populate configuration required by other modules

@@ -35,0 +34,0 @@ // Listen to uncaught exceptions

@@ -8,4 +8,2 @@ /*

var URL = require('url');
var Sugar = require('sugar');
var Express = require('express');

@@ -25,5 +23,5 @@ var MAC = require('mac');

// Servers instances by uri
// Servers instances by uri or name
serversByUri: {}
servers: {}
};

@@ -34,3 +32,3 @@

exports.create = function (options, paths) {
exports.create = function (host, port, options, routes) {

@@ -44,3 +42,3 @@ // Create server object

settings: Object.merge(Defaults.server, options || {}),
settings: Utils.merge(Utils.clone(Defaults.server), options || {}),
express: null,

@@ -53,18 +51,20 @@

// Parse URI and set components
// Set basic configuration
server.settings.uri = server.settings.uri.toLowerCase();
var uri = URL.parse(server.settings.uri);
server.settings.host = {
server.settings.host = host.toLowerCase();
server.settings.port = port;
server.settings.name = (server.settings.name ? server.settings.name.toLowerCase() : (server.settings.host + ':' + server.settings.port));
server.settings.uri = (server.settings.tls ? 'https://' : 'http://') + server.settings.host + ':' + server.settings.port + '/';
domain: uri.hostname,
port: uri.port,
scheme: uri.protocol,
authority: uri.host
};
// Verify no existing instances using the same uri or name
if (internals.servers[server.settings.name]) {
Log.err('Cannot configure multiple server instances using the same name or uri');
process.exit(1);
}
// Create server
if (server.settings.tls.key &&
server.settings.tls.cert) {
if (server.settings.tls) {

@@ -77,3 +77,2 @@ var tls = {

server.settings.tls.isOn = true;
server.express = Express.createServer(tls);

@@ -83,3 +82,2 @@ }

server.settings.tls.isOn = false;
server.express = Express.createServer();

@@ -109,7 +107,11 @@ }

// Load paths
// Add to instance list
for (var i = 0, il = paths.length; i < il; ++i) {
internals.servers[server.settings.name] = server;
server.public.addRoute(paths[i]);
// Add routes
if (routes) {
server.public.addRoutes(routes);
}

@@ -213,6 +215,15 @@ },

server.express.listen(server.settings.host.port, server.settings.host.domain);
Log.info(Process.settings.name + ' Server started at ' + server.settings.uri);
server.express.listen(server.settings.port, server.settings.host);
Log.info(Process.settings.name + ' Server instance started at ' + server.settings.uri);
},
// Stop server
// ----------------------------------------------------------------
stop: function () {
server.express.close();
Log.info(Process.settings.name + ' Server instance stopped at ' + server.settings.uri);
},
// Add server route

@@ -265,3 +276,3 @@ // ----------------------------------------------------------------

res.hapi.err = result;
res.hapi.error = result;
}

@@ -324,2 +335,10 @@ else {

addRoutes: function (routes) {
for (var i = 0, il = routes.length; i < il; ++i) {
server.public.addRoute(routes[i]);
}
},
// Access internal Express server object

@@ -335,6 +354,5 @@ // ----------------------------------------------------------------

// Initialize and add to instances list
// Initialize
server.initialize();
internals.serversByUri[server.settings.uri] = server;

@@ -349,9 +367,9 @@ // Return public interface

exports.instance = function (uri) {
exports.instance = function (name) {
if (uri) {
if (name) {
uri = uri.toLowerCase();
name = name.toLowerCase();
var server = internals.serversByUri[uri];
var server = internals.servers[name];
if (server) {

@@ -368,8 +386,8 @@

var uris = Object.keys(internals.serversByUri);
if (uris.length === 1) {
var names = Object.keys(internals.servers);
if (names.length === 1) {
return internals.serversByUri[uris[0]];
return internals.servers[names[0]];
}
else if (uris.length === 0) {
else if (names.length === 0) {

@@ -389,5 +407,5 @@ return null;

exports.settings = function (uri) {
exports.settings = function (name) {
var server = exports.instance(uri);
var server = exports.instance(name);
if (server) {

@@ -404,2 +422,52 @@

// Add routes to multiple instances
exports.addRoutes = function (arg0, arg1) { // defaultInstances, routes
// Handle optional arguments
var defaultInstances = (arguments.length === 2 ? (arguments[0] instanceof Array ? arguments[0] : [arguments[0]]) : null);
var routes = (arguments.length === 2 ? arguments[1] : arguments[0]);
// Process each route
routes = (routes instanceof Array ? routes : [routes]);
for (var i = 0, il = routes.length; i < il; ++i) {
var route = routes[i];
if (route.instance || defaultInstances) {
// Select instances
var instances = (route.instance ? (route.instance instanceof Array ? route.instance : [route.instance]) : defaultInstances);
for (var r = 0, rl = instances.length; r < rl; ++r) {
var server = internals.servers[instances[r].toLowerCase()];
if (server) {
server.public.addRoute(route);
}
else {
Log.err('Cannot find server instance: ' + instances[r]);
process.exit(1);
}
}
}
else {
// All instances
for (var s in internals.servers) {
if (internals.servers.hasOwnProperty(s)) {
internals.servers[s].public.addRoute(route);
}
}
}
}
};
// Token Authentication

@@ -436,3 +504,3 @@

MAC.authenticate(req, getSession, { isHTTPS: server.settings.tls.isOn }, function (isAuthenticated, session, err) {
MAC.authenticate(req, getSession, { isHTTPS: server.settings.tls }, function (isAuthenticated, session, err) {

@@ -439,0 +507,0 @@ if (isAuthenticated) {

@@ -11,2 +11,3 @@ /*

var Email = require('emailjs');
var Err = require("./error");
var Base64 = require('./base64');

@@ -56,2 +57,46 @@ var Log = require('./log');

// Merge all the properties of source into target; source wins in conflic
exports.merge = function (target, source) {
if (source) {
target = target || (source instanceof Array ? [] : {});
for (var key in source) {
if (source.hasOwnProperty(key)) {
var value = source[key];
if (value &&
typeof value === 'object') {
if (value instanceof Date) {
target[key] = new Date(value.getTime());
}
else if (value instanceof RegExp) {
var flags = '' + (value.global ? 'g' : '') + (value.ignoreCase ? 'i' : '') + (value.multiline ? 'm' : '') + (value.sticky ? 'y' : '');
target[key] = new RegExp(value.source, flags);
}
else {
target[key] = target[key] || (value instanceof Array ? [] : {});
exports.merge(target[key], source[key]);
}
}
else {
target[key] = value;
}
}
}
}
return target;
};
// Remove duplicate items from array

@@ -58,0 +103,0 @@

{
"name" : "hapi",
"description" : "HTTP API Server framework based on Express",
"version" : "0.1.3",
"version" : "0.2.0",
"author" : "Eran Hammer-Lahav <eran@hueniverse.com>",

@@ -14,5 +14,12 @@ "repository" : "git://github.com/walmartlabs/hapi",

"validator": "0.x.x",
"emailjs": "0.x.x",
"sugar": "1.1.x"
"emailjs": "0.x.x"
},
"devDependencies": {
"mocha": "0.x.x",
"request": "2.9.100",
"should": "0.x.x"
},
"scripts": {
"test": "make test"
}
}
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