Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-bigpipe
Advanced tools
bigpipe for nodejs,express,sails,thinkjs,node-web,modular bigpipe for Node
start
, pipe
, end
, very light and transparentPromise
, easy to use and controlnpm install node-bigpipe --save-dev
]. Or [Copy Files into your project directly]jQuery
and bro.bigpipe.js
scripts into html. Or require('node-bigpipe/static/bro.bigpipe')
by webpack
or browserify
.Bigpipe
API of Backend.In Backend, you should use node-bigpipe
to create a bigpipe for response.
In Frontend, you can use bro.bigpipe.js
, or use your own js code to call the bigpipe
from Backend.
Step:
node-bigpipe
module by var Bigpipe = require('node-bigpipe').Bigpipe
var bigpipe = new Bigpipe('pipeName', req, res)
start
api to ouput the pipe and render the unclosed base html framepipe
api to transport to browser the array composed by pipe blocks you createdend
api to finish this bigpipeNote:
If you use nginx/apache
, please check the server buffer
config .
If the response size is small, the nginx won't send pagelet, it will save in its buffer for final response. But you can close nginx buffer/gzip to show the bigpipe effect obviously like this:
location / {
gzip off;
fastcgi_buffer_size 0k;
proxy_buffering off;
...
}
bigpipe.start(viewPath, [data])
: Start render, viewPath
can be a basic html templatebigpipe.pipe(promiseList)
:begin to transport the pipe into reponsebigpipe.end([onEndFn])
: finish the pipebigpipe.render(selector, htmlData)
: Similar with $(selector).html(htmlData)
in browser, set the dom html contentbigpipe.append(selector, htmlData)
: Similar with $(selector).append(htmlData)
, append the dom element contentbigpipe.fire(eventName, data)
: Trigger the event which subscribed in Front End. The event should is used to process the data transported by bigpipe. You can use on
api to subscribe the event in Frontend js.bigpipe.on(eventName).then(data=>{ // deal with data ... })
: Subscribe the eventName, you can use callback function in then
API to process data.bigpie.fire/render/append
Set the dom content, Same with mentioned above in Backend API.The implementation will be put into the tagPagelet, bp
// Here the `bigpipe` parameter is injected by `start` API automatically.
function tagPagelet(bigpipe){
return new Promise((resolve, reject)=>{
let rdata = {
'tag': 'your data'
}
// simulate the asynchronous response
setTimeout(()=>{
let html = '<div><span>TagA</span><span>TagB</span><span>TagC</span><span>TagD</span></div>'
let pipeData = {
'html': html,
'message': 'for tag pipe html',
'css': ['a.css'],
'js': ['b.js'],
}
// Here the `tag` event names will subscribed by Frontend js code.
// Here you can use `render`, `append`, `fire`, it depends on your Backend code
bigpipe.fire('tag', pipeData)
resolve()
}, 3000)
})
}
index (req, res, next, page=1){
let bigpipe = new Bigpipe('karatBP', req, res)
/**
* `bigpipe.start` will inject the _bigpipe_id into the template `data`, So Frontend js can get the `id` by `new Bigpipe('{{_bigpipe_id}}')`
* And in Frontend js, it will export a object named by `_bigpipe_id`. for Example, here will create the window.karatBP object in browser js.
*/
bigpipe.start('view/home')
.pipe([
articlePagelet,
tagPagelet,
// other ...
])
.end()
},
<script type="text/javascript">
// This method will automatically export a object `karatBP` in window. And the `_bigpipe_id` shoud match the definition in backend
new Bigpipe('karatBP')
// You can also use the `_bigpipe_id` parameter from backend by defaultl below:
// new Bigpipe('{{_bigpipe_id}}')
</script>
demo/DemoController.js
:
var Bigpipe = require('node-bigpipe').Bigpipe
// this is a pagelet for pipe, you should return a promise in the pagelet-function.
function tagPagelet(bigpipe){
return new Promise((resolve, reject)=>{
let rdata = {
'tag': 'your data'
}
// simulate the asynchronous response, it may be replaced by DB/IO/NETWORK and other async operations.
setTimeout(()=>{
let html = '<div><span>TagA</span><span>TagB</span><span>TagC</span><span>TagD</span></div>'
let pipeData = {
'html': html,
'message': 'for tag pipe html'
'css': ['a.css'],
'js': ['b.js'],
}
// here the `tag` match the event in frontend. You can use the bigpipe by `on('tag')` in Frontend js code.
bigpipe.fire('tag', pipeData)
resolve()
}, 3000)
})
}
// another pagelet
function articlePagelet(bigpipe){
return new Promise((resolve, reject)=>{
let rdata = {
'article': 'your data'
}
bigpipe.res.render('view/article', rdata, (err, html)=>{
// Here you can use `render`, `append`, `fire`
bigpipe.render('.wrap > .content', html)
resolve()
})
})
}
// here the `index` fn should be bound in router so it can be views by url
// the `view/home` is the basic html template, you can define some container div/elements in this html.
export default {
index (req, res, next, page=1){
let bigpipe = new Bigpipe('karatBP', req, res)
bigpipe.start('view/home')
.pipe([
articlePagelet,
tagPagelet,
// other pagelet...
])
.end()
},
}
<!-- If you want, you can write your own Frontend js to replace `jquery` and `bro.bigpipe` here. -->
<script type="text/javascript" src="/static/jquery.min.js"></script>
<script type="text/javascript" src="/static/bro.bigpipe.js"></script>
<!-- Here will use the bigpipe object transported from Backend -->
<script type="text/javascript">
// The `karatBP` is the bigpipe-id, it should match the Backend definition. Or you can use '{{_bigpipe_id}}' directly.
var karatBP = new Bigpipe('karatBP')
// You can subscribe the events which match the backend API `fire`, like fire('tag', data), then you can `on('tag')` in FE js.
karatBP.on('tag')
.then(function (pageletData) {
console.log(pageletData)
$('#tag').html(pageletData.html)
})
</script>
Difference of usage in Backend:
this
into new Bigpipe()
, like new Bigpipe('xxxBP', http.req, http.res, this)
export default class extends Base {
indexAction(){
let http = this.http;
// Put an additional param: `this`
let bigpipe = new Bigpipe('thinkBP', http.req, http.res, this)
// `start` method use default ThinkJS template path: index.html
// Or bigpipe.sart('xxx') to specific some html template file
bigpipe.start()
.pipe([
tagPagelet,
articlePagelet
// other pagelet...
])
.end()
// Other APIs keep same with above usage.
}
}
Please check the demo code in demo
folder in the repository. And the Frontend js code is in static
folder.
FAQs
bigpipe for nodejs,express,sails,thinkjs,node-web,modular bigpipe for Node
We found that node-bigpipe demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.