Create "Objects" new for each request
I am using express to build a small web application. (Retrieving Compliance Information From Steam)
Since I don't want my Steam Client to be logged all the time, I linked the Steam Login in the response.
I created a simple example app with expression and added a router using
app.use('/user', users);
Now in the user.js file
router.get('/', function(req, res, next) {
if (req.query.id == null || req.query.id == '') {
console.log('wrong');
} else {
var steam = require('steam'),
fs = require('fs'),
csgo = require('csgo'),
bot = new steam.SteamClient(),
CSGO = new csgo.CSGOClient(bot, false);
//... login and event handlers ...
CSGO.on('ready', function () {
console.log('node-csgo ready.');
CSGO.requestRecentGames(CSGO.ToAccountID(req.query.id));
CSGO.on("matchList", function(list) {
res.end(JSON.stringify(list, null, 2));
CSGO.exit();
});
});
}
But now, when I open the web page a second time, the client tells me that I am logged out. Why is the second part not being executed? (create pairs var, login, ...?).
Thank.
If you need more information, I can download the sample application. (I don't know if creating an http server is important for my problem)
source to share
I made node-csgo so I can provide some help.
What you seem to be doing is creating a new steam client every time someone requests your webpage from an expression - and then killing it afterwards, which is not really the best way to accomplish your task. I would recommend trying something like what I did below.
var steam = require('steam'),
fs = require('fs'),
csgo = require('csgo'),
bot = new steam.SteamClient(),
CSGO = new csgo.CSGOClient(bot, false);
// Do your login and event handling here
// Once the CSGO client is ready, then allow the web server to take requests.
CSGO.on('ready', function() {
console.log('node-csgo ready.');
router.get('/', function(req, res, next) {
if (req.query.id == null || req.query.id == '') {
console.log('wrong');
} else {
CSGO.requestRecentGames(CSGO.ToAccountID(req.query.id));
CSGO.on("matchList", function(list) {
res.end(JSON.stringify(list, null, 2));
});
}
});
});
source to share