This is my setup:
My front-end in Angular has a service that calls a /api/status route every 500ms. This works totally fine.
Now I have a button doing a POST request to /api/status/update.
Problem is, when I click on the button multiple times, NodeJs stops taking requests.
Now I did some research and I think it has something to do with the pool-limit of the http-agent.
P.S. The application I am making is running on a local network. So I don't have to be secured for DDOS attacks. I am just trying to find a way to be able to receive unlimited requests from the same client.
I've tried this, but this doesn't work:
var http = require('http')
var express = require('express');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
var request = require('request');
pool = new http.Agent(); //Your pool/agent
http.request({hostname:'localhost', port:3000, path:'/', agent:pool});
request({url:"http://www.google.com", pool:false });
/*= Internal Modules =*/
var routes = require('./server/routes')
var app = express();
app.set('views', __dirname + '/');
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, '/')));
app.use('/', routes);
app.listen(3000, function() {
console.log('Listening on port 3000...')
})
My normal code:
var http = require('http')
var express = require('express');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var path = require('path');
/*= Internal Modules =*/
var routes = require('./server/routes')
var app = express();
app.set('views', __dirname + '/');
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, '/')));
app.use('/', routes);
app.listen(3000, function() {
console.log('Listening on port 3000...')
})
via Soundwave
No comments:
Post a Comment