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

koa-cluster

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-cluster - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

35

lib/http.js

@@ -5,11 +5,9 @@

var http = require('http')
var path = require('path')
var domain = require('domain')
var cluster = require('cluster')
if (process.argv.length !== 1) throw new Error('need a Koa app location')
var args = process.argv
var app = require(path.resolve(process.argv[0]))
var app = require(args[args.length - 1])
var callback = app.callback()
var closing = false // don't try to close the server multiple times

@@ -22,7 +20,5 @@ var server = http.createServer()

})
server.on('error', function (err) {
console.error(err.stack)
})
// custom koa settings
// defaults to http://nodejs.org/api/http.html#http_server_maxheaderscount
server.maxHeadersCount = app.maxHeadersCount || 1000

@@ -33,15 +29,12 @@ server.timeout = app.timeout || 120000

if (err) throw err
if (app.env !== 'test') {
console.log('%s listening on port '
+ this.address().port
+ ', started in %sms',
app.name,
Date.now() - start)
}
console.log('%s listening on port %s, started in %sms',
app.name || 'koa app',
this.address().port,
Date.now() - start)
})
process.on('SIGTERM', function () {
console.log('received SIGTERM signal, closing')
close()
})
// don't try to close the server multiple times
var closing = false
process.on('SIGTERM', close)
process.on('SIGINT', close)

@@ -58,7 +51,5 @@ process.on('exit', function () {

console.error(err.stack)
close(1)
try {
close(1)
cluster.worker.disconnect()
res.statusCode = 500

@@ -82,2 +73,3 @@ res.setHeader('Content-Type', 'text/plain')

if (closing) return
console.log('closing worker %s', cluster.worker.id)
closing = true

@@ -93,2 +85,3 @@

server.close()
cluster.worker.disconnect()
}

6

package.json
{
"name": "koa-cluster",
"description": "Koa clustering and error handling utility",
"version": "0.0.0",
"description": "Koa clustering and domain-based error handling utility",
"version": "0.1.0",
"author": {

@@ -16,3 +16,3 @@ "name": "Jonathan Ong",

},
"bin": "koa-cluster",
"bin": "bin/koa-cluster",
"engines": {

@@ -19,0 +19,0 @@ "node": ">= 0.11.0"

# Koa Cluster
Opinionated clustering and error handling for Koa apps.
Lightweight, opinionated clustering and domain-based error handling for Koa apps.
Use this if you don't want the complexity of other process managers.
## Usage
```bash

@@ -10,2 +13,37 @@ koa-cluster app.js

## Koa App
You must export your Koa app like:
```js
var app = module.exports = koa()
```
Make sure you don't create a `http` server yourself.
Don't call `app.listen()`.
This will handle it automatically.
### Check Continue
This automatically utilizes the `checkContinue` event.
You should handle this wherever appropriate in your Koa app:
```js
app.use(function* () {
if (this.req.checkContinue) this.res.writeContinue();
var body = yield parse(this);
})
```
### Settings
Custom settings are checked on the `app` that aren't part of Koa.
You can set them however you'd like.
These settings are:
- `name` - your app's name
- `port`
- `maxHeadersCount`
- `timeout`
## License

@@ -12,0 +50,0 @@

Sorry, the diff of this file is not supported yet

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