0

The client library js file is not loading. Trying to load socket.io into my project but the client is not detecting the javascript library that is supposed to be served automatically. here is my code.

var express = require('express') , passport = require('passport') , util = require('util') , session = require('express-session') , SteamStrategy = require('../../').Strategy , Steam = require('machinepack-steam') , path = require('path') , app = express() , http = require('http') , socket = require('socket.io') ; app.set('port', process.env.PORT || 2053); var server = http.createServer(app).listen(app.get('port'), function(){ console.log("Express server listening on port " + app.get('port')); }); var io = socket.listen(server); io.sockets.on('connection', function () { console.log('hello world im a hot socket'); }); var steamkey = 'redacted'; passport.serializeUser(function(user, done) { done(null, user); }); passport.deserializeUser(function(obj, done) { done(null, obj); }); passport.use(new SteamStrategy({ returnURL: 'https://get-a.team/auth/steam/return', realm: 'https://get-a.team', apiKey: steamkey }, function(identifier, profile, done) { // asynchronous verification, for effect... process.nextTick(function () { profile.identifier = identifier; return done(null, profile); }); } )); app.set('views', __dirname + '/views'); app.set('view engine', 'ejs'); app.use(session({ secret: 'your secret', name: 'name of session id', resave: true, saveUninitialized: true})); app.use(passport.initialize()); app.use(passport.session()); app.use(express.static(path.join('public'))); app.get('/', function(req, res){	if(req.user){	res.redirect('/account');	} else {	res.render('index', { user: req.user });	} }); app.get('/search/:appid', ensureAuthenticated, function(req, res){	if(Number.isInteger(+req.params.appid)){	res.render('search', { user: req.user, appid: req.params.appid });	} else {	res.render('error', { user: req.user, error: "Wrong url format "+req.params.appid });	} }) app.get('/account', ensureAuthenticated, function(req, res){	Steam.getOwnedGames({ steamid: req.user.id, key: steamkey, include_appinfo: 1, include_played_free_games: 1, appids_filter: [],	}).exec({ // An unexpected error occurred. error: function(err) {	console.error(err); }, // OK. success: function(result) {	//console.log(result);	// save every game that isnt already saved	res.render('account', { user: req.user, games: result }); },	}); }); app.get('/logout', function(req, res){ req.logout(); res.redirect('/'); }); app.get('/auth/steam', passport.authenticate('steam', { failureRedirect: '/' }), function(req, res) { res.redirect('/'); }); app.get('/auth/steam/return', passport.authenticate('steam', { failureRedirect: '/' }), function(req, res) { res.redirect('/account'); }); app.listen(3000); function ensureAuthenticated(req, res, next) { if (req.isAuthenticated()) { return next(); } res.redirect('/'); }

Any help will be greatly appreciated

I've tried many different ways to include the socket library online but none works, even code copied directly from the socket.io website.

I tried localhost:2053/socket.io/socket.io.js and it still won't work. Not sure what im doing wrong

2
  • How are you loading the SteamStrategy? It seems there is something wrong with the import unless you are pointing to an index file. Commented Feb 14, 2018 at 11:30
  • The steam code works just fine. It is a clone of this git. in the /example/signon folder github.com/liamcurry/passport-steam Commented Feb 14, 2018 at 11:33

1 Answer 1

1

Figured it out. Had to reload socket.io to a different port:

... , app2 = require('express')() , http2 = require('http').Server(app2) ; var io = require('socket.io')(http2); io.on('connection', function(socket){ console.log('a user connected'); }); app2.get('/', function(req, res){ res.send('<h1>Hello world</h1>'); }); http2.listen(2085, function(){ console.log('listening on *:2085'); });

the create a nginx rule to serve the lib from that port:

location /route/ { rewrite ^/route/?(.*)$ /$1 break; proxy_pass http://127.0.0.1:2085; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

and finally load it from the client end:

 <script src="/route/socket.io/socket.io.js"></script> 

if anyone knows the correct way of doing it, please let me know. This works though, feels quite like forcing a round peg in a square hole.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.