![38% of CISOs Fear They’re Not Moving Fast Enough on AI](https://cdn.sanity.io/images/cgdhsj6q/production/faa0bc28df98f791e11263f8239b34207f84b86f-1024x1024.webp?w=400&fit=max&auto=format)
Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Event based server wrapper that adds a middleware stack. Uses available harmony features.
A name from some random website that generated random names. No meaning. Not going to use any buzz-words like "Opinionated" or "super ballsy framework to make your cat sing showtunes"...
The problem with existing frameworks is they do a lot more than the average developer uses, this is part of the industry standard for some reason. Everything needs to do everything. bullshit
More importantly, there aren't many frameworks that strive to use the best of the available technology and developers happily settle for living in an umma-gumma land of dreams.
Most modules aren't even strict compliant which is a ball-ache for developers who want to use a strict environment.
Just a simple wrapper for the http object, a bit like connect but strict compatible and using Harmony (ES6) features as they become available for the type of developer that might say "Yolo" (even sarcastically)
To create a server you must first know how to run Node with strict mode enabled. This breaks a LOT of modules. a LOT of modules, actually most modules. I can't stress that enough, shame on JS devs.
Also; unfortunately, due to the harmony-ess of this project, this is also not compatible with Node JS versions < 0.11.7
; although I recommend 0.11.9
since the 0.11.7
release has a few bugs from what I can see on 26/2/2014.
This version requirement will increase as more Harmony features are added to V8 and decrease as they stabalise but development of these futuristic strains will happen on new branches specifically for people living on the edge. YOLO.
Please don't report a bug if you're getting errors and can trace it to a module that isn't strict compliant or just has a bug in it. Use your noggin and node debug --harmony --use_strict yourapp.js
to find your culprit and then report bugs.
To run Coju you must run node with two flags:
NODE_ENV=development node --harmony --use_strict yourapp.js
Otherwise you're going to get a lot of errors around the new syntax.
To get started you'll need to create a server, this is pretty simple to be honest as this is just a wrapper for dealing with some normal http stuff in Node JS.
{
require('coju').listen(1811);
}
Much like Connect (which, by the way is awesome) Coju has a "middleware" philosophy with slightly less verbosity/guesswork.
Http.Server
is an EventEmitter
and will work that way.###Building your project on coju
Building a site on coju is like building any other node/Connect project, the concept of modules, servers and all that other stuff is the same. All coju offers is a neatly gift-wrapped http service for capturing requests and modifying responses via a series of middleware.
Your main entry point will look something like this, for a simple hello world example
index.js
{
let coju = require('coju');
coju.on('request', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end("<h1>Hello World.</h1>");
});
coju.listen(1811);
}
While the notion of a built in router seems clever and helpful, any modules that aren't core to the http service should be external and thus managed so. All extra functionality will be handled this way going forwards.
coju
has a simple api and a very small number of "types" to keep shit simple, frameworks these days all seem convoluted and voodoo. Not coju
.
##coju-core API
See here for documentation on coju core.
####coju()
type Function
access Public
return Function
stability 6: Testing
coju
is a class (in the loosest possible usage of the word until we get classes/modules in Harmony) and simply interjects a very lightweight system in the middle for using middleware easily.
{
require('coju').listen(1811);
}
####coju.configure(json options)
type Function
access Public
return void
stability 6: Testing
The default configuration of coju
should keep most people happy but there are some bottleneck features that might not be necessary that can be switched off easily inside of this function. The below example shows all currently configurable options.
Debug will be true if your NODE_ENV
is set to development and false if it is equal to anything else.
coju.configure({
"debug" : true,
"events" : {
"request" : true,
"close" : true,
"checkContinue" : true,
"continue" : true,
"connect" : true,
"upgrade" : true,
"clientError" : true
}
});
####coju.on|off(string eventName, Function callback)
type Function
access Public
return Void
stability 6: Testing
coju
uses Nodes default list of events from the http.Server
object, to view all the available event subscriptions please read the documentation.
Coercly, all the above events can be unsubscribed from by using the coju.off
method with a similar syntax.
To use this most efficiently, USE NAMED FUNCTIONS otherwise it has to index and check indexes and blah blah. Named functions simply win.
####Subscription
{
let coju = require('coju');
coju.on('request', function myFirstCojuMiddleware(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello World.");
});
coju.listen(1811);
}
####Unsubscribing from events
{
let coju = require('coju');
coju.on('request', function myFirstCojuMiddleware(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello World.");
});
coju.off('request', function myFirstCojuMiddleware(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello World.");
});
coju.listen(1811);
}
Unlike with Express/Connect middleware is not registered via a use
call, if we're writing a module we imply it's usage by subscribing to our varying events (yes, if you configure coju to not fire these events all of your middleware will stop working) see this example, a simple IP blocker.
#####index.js
{
let
coju = require('coju'),
ipban = require('./middleware/ip-ban');
// On all requests, check for banned IP addresses.
ipban(coju);
// Create server
coju.listen(1811);
}
#####middleware/ipban.js
{
function getRemoteIPAddress(req) {
return (req.headers['x-forwarded-for'] || '').split(',')[0]
|| req.connection.remoteAddress;
}
function ipban(req, res) {
let banned = ['8.8.8.8', '127.0.0.1'];
if (banned.indexOf(getRemoteIPAddress(req))) {
res.writeHead(403, {'Content-Type': 'text/plain'});
res.end("Nope. No access, banned IP.");
}
}
module.exports = function(coju) {
coju('request', ipban);
};
}
FAQs
Event based server wrapper that adds a middleware stack. Uses available harmony features.
The npm package coju receives a total of 0 weekly downloads. As such, coju popularity was classified as not popular.
We found that coju demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.