forked from enviPath/enviPy
Current Dev State
This commit is contained in:
71
static/js/ketcher2/node_modules/stacked/README.md
generated
vendored
Normal file
71
static/js/ketcher2/node_modules/stacked/README.md
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
[](https://travis-ci.org/fgnass/stacked)
|
||||
|
||||
# stacked
|
||||
|
||||
Stacked is a stand-alone, lightweight, zero-dependency version of
|
||||
[connect](http://www.senchalabs.org/connect/)'s middleware infrastructure.
|
||||
|
||||
It can be used to create modules that bundle multiple middleware functions
|
||||
into one.
|
||||
|
||||
### Installation
|
||||
|
||||
```
|
||||
npm install stacked --save
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```javascript
|
||||
var stacked = require('stacked')
|
||||
|
||||
/**
|
||||
* A middleware that logs the requested URL.
|
||||
*/
|
||||
function middleware(req, res, next) {
|
||||
console.log('url:', req.url)
|
||||
next()
|
||||
}
|
||||
|
||||
/**
|
||||
* A middleware that logs the requested URL (with the mount point stripped)
|
||||
* as well as the original URL.
|
||||
*/
|
||||
function mounted(req, res, next) {
|
||||
console.log('url:', req.url, 'realUrl:', req.realUrl)
|
||||
next()
|
||||
}
|
||||
|
||||
module.exports = stacked()
|
||||
.use(middleware)
|
||||
.mount('/path', mounted)
|
||||
```
|
||||
|
||||
### Run Tests
|
||||
|
||||
```
|
||||
npm install
|
||||
npm test
|
||||
```
|
||||
|
||||
## The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Felix Gnass
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
57
static/js/ketcher2/node_modules/stacked/package.json
generated
vendored
Normal file
57
static/js/ketcher2/node_modules/stacked/package.json
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"_from": "stacked@^1.1.1",
|
||||
"_id": "stacked@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-LH+jjMfjejQRp3zY55LeRI+faXU=",
|
||||
"_location": "/stacked",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "stacked@^1.1.1",
|
||||
"name": "stacked",
|
||||
"escapedName": "stacked",
|
||||
"rawSpec": "^1.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/budo"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/stacked/-/stacked-1.1.1.tgz",
|
||||
"_shasum": "2c7fa38cc7e37a3411a77cd8e792de448f9f6975",
|
||||
"_spec": "stacked@^1.1.1",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/budo",
|
||||
"author": {
|
||||
"name": "Felix Gnass",
|
||||
"email": "fgnass@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fgnass/stacked/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "bundle multiple middleware functions into one stack",
|
||||
"devDependencies": {
|
||||
"chai": "^1.9.1",
|
||||
"connect": "^3.0.1",
|
||||
"mocha": "^1.20.1",
|
||||
"supertest": "^0.13.0"
|
||||
},
|
||||
"homepage": "https://github.com/fgnass/stacked",
|
||||
"keywords": [
|
||||
"connect",
|
||||
"middleware",
|
||||
"stack"
|
||||
],
|
||||
"main": "stacked.js",
|
||||
"name": "stacked",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/fgnass/stacked.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test/ --reporter spec"
|
||||
},
|
||||
"version": "1.1.1"
|
||||
}
|
||||
67
static/js/ketcher2/node_modules/stacked/stacked.js
generated
vendored
Normal file
67
static/js/ketcher2/node_modules/stacked/stacked.js
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
var URL = require('url')
|
||||
|
||||
module.exports = function(/* fn1, fn2, ... */) {
|
||||
var handle = function (req, res, out) {
|
||||
var i = 0
|
||||
function next(err) {
|
||||
var layer = handle.layers[i++]
|
||||
|
||||
if (!layer || res.headersSent) {
|
||||
// all done
|
||||
if (out) return out(err) // delegate to parent
|
||||
|
||||
if (err && res.statusCode < 400) res.statusCode = err.status || 500
|
||||
else res.statusCode = 404
|
||||
|
||||
return res.end()
|
||||
}
|
||||
|
||||
try {
|
||||
layer(req, res, next)
|
||||
}
|
||||
catch (e) {
|
||||
next(e)
|
||||
}
|
||||
}
|
||||
next()
|
||||
}
|
||||
|
||||
handle.layers = Array.prototype.slice.call(arguments)
|
||||
|
||||
handle.use = function(fn) {
|
||||
if (typeof fn == 'object' && fn.handle) fn = fn.handle.bind(fn)
|
||||
handle.layers.push(fn)
|
||||
return this
|
||||
}
|
||||
|
||||
handle.mount = function(path, fn) {
|
||||
return this.use(sub(path, fn))
|
||||
}
|
||||
|
||||
return handle
|
||||
}
|
||||
|
||||
function sub(mount, fn) {
|
||||
if (mount.substr(-1) != '/') mount += '/'
|
||||
if (typeof fn == 'object' && fn.handle) fn = fn.handle.bind(fn)
|
||||
|
||||
return function(req, res, next) {
|
||||
var url = req.url
|
||||
, uri = req.uri
|
||||
|
||||
if (url.substr(0, mount.length) !== mount && url.substr(0, mount.length) + '/' !== mount) return next()
|
||||
|
||||
// modify the URL
|
||||
if (!req.realUrl) req.realUrl = url
|
||||
|
||||
req.url = url.substr(mount.length-1)
|
||||
if (req.uri) req.uri = URL.parse(req.url)
|
||||
|
||||
fn(req, res, function(err) {
|
||||
// reset the URL
|
||||
req.url = url
|
||||
req.uri = uri
|
||||
next(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
111
static/js/ketcher2/node_modules/stacked/test/stacked.js
generated
vendored
Normal file
111
static/js/ketcher2/node_modules/stacked/test/stacked.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
/* global describe, it */
|
||||
|
||||
var stacked = require('../stacked')
|
||||
, expect = require('chai').expect
|
||||
, connect = require('connect')
|
||||
, request = require('supertest')
|
||||
|
||||
describe('stacked()', function () {
|
||||
describe('.use(layer)', function () {
|
||||
it('execute as middleware', function (done) {
|
||||
var app = connect()
|
||||
var pack = stacked()
|
||||
var middleware1Called = false
|
||||
var middleware2Called = false
|
||||
|
||||
pack.use(function (req, res, next) {
|
||||
middleware1Called = true
|
||||
next()
|
||||
})
|
||||
|
||||
pack.use(function (req, res, next) {
|
||||
middleware2Called = true
|
||||
res.statusCode = 200
|
||||
res.end()
|
||||
})
|
||||
|
||||
app.use(pack)
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(function () {
|
||||
expect(middleware1Called).to.equal(true)
|
||||
expect(middleware2Called).to.equal(true)
|
||||
})
|
||||
.end(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.use(layer, layer)', function () {
|
||||
it('execute as middleware', function (done) {
|
||||
var app = connect()
|
||||
var middleware1Called = false
|
||||
var middleware2Called = false
|
||||
var pack = stacked(
|
||||
function (req, res, next) {
|
||||
middleware1Called = true
|
||||
next()
|
||||
},
|
||||
function (req, res, next) {
|
||||
middleware2Called = true
|
||||
res.statusCode = 200
|
||||
res.end()
|
||||
}
|
||||
)
|
||||
|
||||
app.use(pack)
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect(function () {
|
||||
expect(middleware1Called).to.equal(true)
|
||||
expect(middleware2Called).to.equal(true)
|
||||
})
|
||||
.end(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('.layers', function () {
|
||||
it('is exposed on object', function () {
|
||||
var pack = stacked()
|
||||
var layer = function (req, res, next) {
|
||||
next()
|
||||
}
|
||||
pack.use(layer)
|
||||
|
||||
expect(pack.layers.length).to.equal(1)
|
||||
expect(pack.layers[0].toString()).to.equal(layer.toString())
|
||||
})
|
||||
})
|
||||
|
||||
describe('.mount(path, fn)', function () {
|
||||
it('executes at the given path', function (done) {
|
||||
var app = connect()
|
||||
var pack = stacked()
|
||||
var mountedMiddleware1Called = false
|
||||
var mountedMiddleware2Called = false
|
||||
|
||||
pack.mount('/mount1', function (req, res, next) {
|
||||
mountedMiddleware1Called = true
|
||||
next()
|
||||
})
|
||||
|
||||
pack.mount('/mount2', function (req, res, next) {
|
||||
mountedMiddleware2Called = true
|
||||
next()
|
||||
})
|
||||
|
||||
app.use(pack)
|
||||
|
||||
request(app)
|
||||
.get('/mount1')
|
||||
.expect(function () {
|
||||
expect(mountedMiddleware1Called).to.equal(true)
|
||||
expect(mountedMiddleware2Called).to.equal(false)
|
||||
})
|
||||
.end(done)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user