CORS request did not succeed using socket.io
I am trying to build a login system with socket.io and node. However I keep getting the error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:4000/socket.io/?EIO=3&transport=polling&t=MShU2AZ. (Reason: CORS request did not succeed).
I have installed cors with npm and just cant seem to get it working does anyone by chance know what I am doing wrong?
Thank you for your time.
server.js
var express = require('express');
const app = require('express')()
const mongo = require('mongodb').MongoClient;
const port = 3000;
const http = require('http').Server(app);
const client = require('socket.io').listen(http);
var mongoose = require('mongoose');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var cors = require('cors');
var path = require('path');
app.use(cors({credentials: true, origin: true}))
//set app to use ejs
app.set('view engine', 'ejs')
// set views dir for ejs
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// serve static files from template
app.use(express.static(__dirname + '/'));
// include routes
var routes = require('./routes/router');
app.use('/', routes);
// Connect to mongo
mongoose.connect('...', function(err, db) {
if (err) {
throw err;
}
// Set db log connection wass success
var db = mongoose.connection;
console.log('MongoDB connected...');
///////////////////////// not sure if needed
//use sessions for tracking logins
app.use(session({
secret: 'work hard',
resave: false,
saveUninitialized: true,
store: new MongoStore({
mongooseConnection: db
})
}));
///////////////////////////////
// Connect to Socket.io
client.on('connection', function(socket) {
//Retrieve user model
var userModel = require('./models/user');
// Handle user registration
socket.on('register', function(data) {
console.log(data.Username);
//The data that will get sent.
var newUser = userModel({
Username: data.Username,
Password: data.Password
})
// Save new user data
newUser.save(function(err) {
console.log("New user registered");
})
});
// Handle user login
socket.on('login', function(data) {
// console.log(data.Username);
// ["I'm the data that will get sent."
usernameFindMe = data.Username;
passwordFindMe = data.Password;
userModel.findOne({
Username: usernameFindMe,
Password: passwordFindMe
}, function(err, user) {
if (err) {
console.log('err');
}
if (!user) {
console.log('OH NOOOOOOOOOO');
} else {
console.log('yay');
module.exports.yourUserName = usernameFindMe;
var destination = '/';
client.emit('redirect', destination);
}
})
});
});
});
//Start the Server
http.listen(port, function() {
console.log('listening on *:' + port);
});
router.js
var express = require('express');
var router = express.Router();
//get variables from server
var sourceFile = require('./../server');
// Default Variables
userName = 'Not Logged In';
// GET route for dashboard
router.get('/', function(req, res, next) {
res.render('index.ejs', {
});
// set variables
function setRandom() {
if (sourceFile.yourUserName == null){
userName = 'Not Logged In';
}
else{
userName = sourceFile.yourUserName;
console.log(userName);
}
}
setRandom();
setInterval(setRandom, 200);
});
// GET route for dashboard
router.get('/register', function(req, res, next) {
res.render('register.ejs', {
});
// set variables
userName = sourceFile.yourUserName;
// log username for development
console.log(userName);
});
module.exports = router;
index.ejs
<div>
Register
<input type="text" id="usernameRegister" class="form-control" placeholder="Enter name...">
<input type="text" id="passwordRegister" class="form-control" placeholder="EnterPassword...">
<button id="userRegister" class="btn btn-danger" onclick="setTimeout(RegisterRedirect, 100)">Register</button>
</div>
<script>
// redirect from register page back to the login page for browsers
function RegisterRedirect() {
window.location.href = "/";
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
(function() {
var element = function(id) {
return document.getElementById(id);
}
//client side socket.io
// Get Elements
var UserRegister = element('userRegister')
var UserLogin = element('userLogin');
// Connect to socket.io
var socket = io({transports: ['websocket'], upgrade: false});
// Check for connection
if (socket !== undefined) {
console.log('Connected to socket...');
// Handle Register
UserRegister.addEventListener('click', function() {
socket.emit('register', {
Username: usernameRegister.value,
Password: passwordRegister.value
})
});
// Handle Login
UserLogin.addEventListener('click', function() {
socket.emit('login', {
Username: usernameLogin.value,
Password: passwordLogin.value
})
});
socket.on('redirect', function(destination) {
setTimeout(function() {
window.location.href = destination;
}, 300);
});
}
})();
</script>
changing
var socket = io.connect('http://127.0.0.1:3000');
to
var socket = io({transports: ['websocket'], upgrade: false});
fixed the problem
javascript node.js sockets cors
add a comment |
I am trying to build a login system with socket.io and node. However I keep getting the error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:4000/socket.io/?EIO=3&transport=polling&t=MShU2AZ. (Reason: CORS request did not succeed).
I have installed cors with npm and just cant seem to get it working does anyone by chance know what I am doing wrong?
Thank you for your time.
server.js
var express = require('express');
const app = require('express')()
const mongo = require('mongodb').MongoClient;
const port = 3000;
const http = require('http').Server(app);
const client = require('socket.io').listen(http);
var mongoose = require('mongoose');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var cors = require('cors');
var path = require('path');
app.use(cors({credentials: true, origin: true}))
//set app to use ejs
app.set('view engine', 'ejs')
// set views dir for ejs
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// serve static files from template
app.use(express.static(__dirname + '/'));
// include routes
var routes = require('./routes/router');
app.use('/', routes);
// Connect to mongo
mongoose.connect('...', function(err, db) {
if (err) {
throw err;
}
// Set db log connection wass success
var db = mongoose.connection;
console.log('MongoDB connected...');
///////////////////////// not sure if needed
//use sessions for tracking logins
app.use(session({
secret: 'work hard',
resave: false,
saveUninitialized: true,
store: new MongoStore({
mongooseConnection: db
})
}));
///////////////////////////////
// Connect to Socket.io
client.on('connection', function(socket) {
//Retrieve user model
var userModel = require('./models/user');
// Handle user registration
socket.on('register', function(data) {
console.log(data.Username);
//The data that will get sent.
var newUser = userModel({
Username: data.Username,
Password: data.Password
})
// Save new user data
newUser.save(function(err) {
console.log("New user registered");
})
});
// Handle user login
socket.on('login', function(data) {
// console.log(data.Username);
// ["I'm the data that will get sent."
usernameFindMe = data.Username;
passwordFindMe = data.Password;
userModel.findOne({
Username: usernameFindMe,
Password: passwordFindMe
}, function(err, user) {
if (err) {
console.log('err');
}
if (!user) {
console.log('OH NOOOOOOOOOO');
} else {
console.log('yay');
module.exports.yourUserName = usernameFindMe;
var destination = '/';
client.emit('redirect', destination);
}
})
});
});
});
//Start the Server
http.listen(port, function() {
console.log('listening on *:' + port);
});
router.js
var express = require('express');
var router = express.Router();
//get variables from server
var sourceFile = require('./../server');
// Default Variables
userName = 'Not Logged In';
// GET route for dashboard
router.get('/', function(req, res, next) {
res.render('index.ejs', {
});
// set variables
function setRandom() {
if (sourceFile.yourUserName == null){
userName = 'Not Logged In';
}
else{
userName = sourceFile.yourUserName;
console.log(userName);
}
}
setRandom();
setInterval(setRandom, 200);
});
// GET route for dashboard
router.get('/register', function(req, res, next) {
res.render('register.ejs', {
});
// set variables
userName = sourceFile.yourUserName;
// log username for development
console.log(userName);
});
module.exports = router;
index.ejs
<div>
Register
<input type="text" id="usernameRegister" class="form-control" placeholder="Enter name...">
<input type="text" id="passwordRegister" class="form-control" placeholder="EnterPassword...">
<button id="userRegister" class="btn btn-danger" onclick="setTimeout(RegisterRedirect, 100)">Register</button>
</div>
<script>
// redirect from register page back to the login page for browsers
function RegisterRedirect() {
window.location.href = "/";
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
(function() {
var element = function(id) {
return document.getElementById(id);
}
//client side socket.io
// Get Elements
var UserRegister = element('userRegister')
var UserLogin = element('userLogin');
// Connect to socket.io
var socket = io({transports: ['websocket'], upgrade: false});
// Check for connection
if (socket !== undefined) {
console.log('Connected to socket...');
// Handle Register
UserRegister.addEventListener('click', function() {
socket.emit('register', {
Username: usernameRegister.value,
Password: passwordRegister.value
})
});
// Handle Login
UserLogin.addEventListener('click', function() {
socket.emit('login', {
Username: usernameLogin.value,
Password: passwordLogin.value
})
});
socket.on('redirect', function(destination) {
setTimeout(function() {
window.location.href = destination;
}, 300);
});
}
})();
</script>
changing
var socket = io.connect('http://127.0.0.1:3000');
to
var socket = io({transports: ['websocket'], upgrade: false});
fixed the problem
javascript node.js sockets cors
You can't access something on127.0.0.1:4000
from127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
1
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38
add a comment |
I am trying to build a login system with socket.io and node. However I keep getting the error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:4000/socket.io/?EIO=3&transport=polling&t=MShU2AZ. (Reason: CORS request did not succeed).
I have installed cors with npm and just cant seem to get it working does anyone by chance know what I am doing wrong?
Thank you for your time.
server.js
var express = require('express');
const app = require('express')()
const mongo = require('mongodb').MongoClient;
const port = 3000;
const http = require('http').Server(app);
const client = require('socket.io').listen(http);
var mongoose = require('mongoose');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var cors = require('cors');
var path = require('path');
app.use(cors({credentials: true, origin: true}))
//set app to use ejs
app.set('view engine', 'ejs')
// set views dir for ejs
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// serve static files from template
app.use(express.static(__dirname + '/'));
// include routes
var routes = require('./routes/router');
app.use('/', routes);
// Connect to mongo
mongoose.connect('...', function(err, db) {
if (err) {
throw err;
}
// Set db log connection wass success
var db = mongoose.connection;
console.log('MongoDB connected...');
///////////////////////// not sure if needed
//use sessions for tracking logins
app.use(session({
secret: 'work hard',
resave: false,
saveUninitialized: true,
store: new MongoStore({
mongooseConnection: db
})
}));
///////////////////////////////
// Connect to Socket.io
client.on('connection', function(socket) {
//Retrieve user model
var userModel = require('./models/user');
// Handle user registration
socket.on('register', function(data) {
console.log(data.Username);
//The data that will get sent.
var newUser = userModel({
Username: data.Username,
Password: data.Password
})
// Save new user data
newUser.save(function(err) {
console.log("New user registered");
})
});
// Handle user login
socket.on('login', function(data) {
// console.log(data.Username);
// ["I'm the data that will get sent."
usernameFindMe = data.Username;
passwordFindMe = data.Password;
userModel.findOne({
Username: usernameFindMe,
Password: passwordFindMe
}, function(err, user) {
if (err) {
console.log('err');
}
if (!user) {
console.log('OH NOOOOOOOOOO');
} else {
console.log('yay');
module.exports.yourUserName = usernameFindMe;
var destination = '/';
client.emit('redirect', destination);
}
})
});
});
});
//Start the Server
http.listen(port, function() {
console.log('listening on *:' + port);
});
router.js
var express = require('express');
var router = express.Router();
//get variables from server
var sourceFile = require('./../server');
// Default Variables
userName = 'Not Logged In';
// GET route for dashboard
router.get('/', function(req, res, next) {
res.render('index.ejs', {
});
// set variables
function setRandom() {
if (sourceFile.yourUserName == null){
userName = 'Not Logged In';
}
else{
userName = sourceFile.yourUserName;
console.log(userName);
}
}
setRandom();
setInterval(setRandom, 200);
});
// GET route for dashboard
router.get('/register', function(req, res, next) {
res.render('register.ejs', {
});
// set variables
userName = sourceFile.yourUserName;
// log username for development
console.log(userName);
});
module.exports = router;
index.ejs
<div>
Register
<input type="text" id="usernameRegister" class="form-control" placeholder="Enter name...">
<input type="text" id="passwordRegister" class="form-control" placeholder="EnterPassword...">
<button id="userRegister" class="btn btn-danger" onclick="setTimeout(RegisterRedirect, 100)">Register</button>
</div>
<script>
// redirect from register page back to the login page for browsers
function RegisterRedirect() {
window.location.href = "/";
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
(function() {
var element = function(id) {
return document.getElementById(id);
}
//client side socket.io
// Get Elements
var UserRegister = element('userRegister')
var UserLogin = element('userLogin');
// Connect to socket.io
var socket = io({transports: ['websocket'], upgrade: false});
// Check for connection
if (socket !== undefined) {
console.log('Connected to socket...');
// Handle Register
UserRegister.addEventListener('click', function() {
socket.emit('register', {
Username: usernameRegister.value,
Password: passwordRegister.value
})
});
// Handle Login
UserLogin.addEventListener('click', function() {
socket.emit('login', {
Username: usernameLogin.value,
Password: passwordLogin.value
})
});
socket.on('redirect', function(destination) {
setTimeout(function() {
window.location.href = destination;
}, 300);
});
}
})();
</script>
changing
var socket = io.connect('http://127.0.0.1:3000');
to
var socket = io({transports: ['websocket'], upgrade: false});
fixed the problem
javascript node.js sockets cors
I am trying to build a login system with socket.io and node. However I keep getting the error
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:4000/socket.io/?EIO=3&transport=polling&t=MShU2AZ. (Reason: CORS request did not succeed).
I have installed cors with npm and just cant seem to get it working does anyone by chance know what I am doing wrong?
Thank you for your time.
server.js
var express = require('express');
const app = require('express')()
const mongo = require('mongodb').MongoClient;
const port = 3000;
const http = require('http').Server(app);
const client = require('socket.io').listen(http);
var mongoose = require('mongoose');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var cors = require('cors');
var path = require('path');
app.use(cors({credentials: true, origin: true}))
//set app to use ejs
app.set('view engine', 'ejs')
// set views dir for ejs
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// serve static files from template
app.use(express.static(__dirname + '/'));
// include routes
var routes = require('./routes/router');
app.use('/', routes);
// Connect to mongo
mongoose.connect('...', function(err, db) {
if (err) {
throw err;
}
// Set db log connection wass success
var db = mongoose.connection;
console.log('MongoDB connected...');
///////////////////////// not sure if needed
//use sessions for tracking logins
app.use(session({
secret: 'work hard',
resave: false,
saveUninitialized: true,
store: new MongoStore({
mongooseConnection: db
})
}));
///////////////////////////////
// Connect to Socket.io
client.on('connection', function(socket) {
//Retrieve user model
var userModel = require('./models/user');
// Handle user registration
socket.on('register', function(data) {
console.log(data.Username);
//The data that will get sent.
var newUser = userModel({
Username: data.Username,
Password: data.Password
})
// Save new user data
newUser.save(function(err) {
console.log("New user registered");
})
});
// Handle user login
socket.on('login', function(data) {
// console.log(data.Username);
// ["I'm the data that will get sent."
usernameFindMe = data.Username;
passwordFindMe = data.Password;
userModel.findOne({
Username: usernameFindMe,
Password: passwordFindMe
}, function(err, user) {
if (err) {
console.log('err');
}
if (!user) {
console.log('OH NOOOOOOOOOO');
} else {
console.log('yay');
module.exports.yourUserName = usernameFindMe;
var destination = '/';
client.emit('redirect', destination);
}
})
});
});
});
//Start the Server
http.listen(port, function() {
console.log('listening on *:' + port);
});
router.js
var express = require('express');
var router = express.Router();
//get variables from server
var sourceFile = require('./../server');
// Default Variables
userName = 'Not Logged In';
// GET route for dashboard
router.get('/', function(req, res, next) {
res.render('index.ejs', {
});
// set variables
function setRandom() {
if (sourceFile.yourUserName == null){
userName = 'Not Logged In';
}
else{
userName = sourceFile.yourUserName;
console.log(userName);
}
}
setRandom();
setInterval(setRandom, 200);
});
// GET route for dashboard
router.get('/register', function(req, res, next) {
res.render('register.ejs', {
});
// set variables
userName = sourceFile.yourUserName;
// log username for development
console.log(userName);
});
module.exports = router;
index.ejs
<div>
Register
<input type="text" id="usernameRegister" class="form-control" placeholder="Enter name...">
<input type="text" id="passwordRegister" class="form-control" placeholder="EnterPassword...">
<button id="userRegister" class="btn btn-danger" onclick="setTimeout(RegisterRedirect, 100)">Register</button>
</div>
<script>
// redirect from register page back to the login page for browsers
function RegisterRedirect() {
window.location.href = "/";
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
(function() {
var element = function(id) {
return document.getElementById(id);
}
//client side socket.io
// Get Elements
var UserRegister = element('userRegister')
var UserLogin = element('userLogin');
// Connect to socket.io
var socket = io({transports: ['websocket'], upgrade: false});
// Check for connection
if (socket !== undefined) {
console.log('Connected to socket...');
// Handle Register
UserRegister.addEventListener('click', function() {
socket.emit('register', {
Username: usernameRegister.value,
Password: passwordRegister.value
})
});
// Handle Login
UserLogin.addEventListener('click', function() {
socket.emit('login', {
Username: usernameLogin.value,
Password: passwordLogin.value
})
});
socket.on('redirect', function(destination) {
setTimeout(function() {
window.location.href = destination;
}, 300);
});
}
})();
</script>
changing
var socket = io.connect('http://127.0.0.1:3000');
to
var socket = io({transports: ['websocket'], upgrade: false});
fixed the problem
javascript node.js sockets cors
javascript node.js sockets cors
edited Nov 21 '18 at 11:29
rolle
asked Nov 19 '18 at 10:20
rollerolle
275
275
You can't access something on127.0.0.1:4000
from127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
1
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38
add a comment |
You can't access something on127.0.0.1:4000
from127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
1
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38
You can't access something on
127.0.0.1:4000
from 127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You can't access something on
127.0.0.1:4000
from 127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
1
1
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372510%2fcors-request-did-not-succeed-using-socket-io%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372510%2fcors-request-did-not-succeed-using-socket-io%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can't access something on
127.0.0.1:4000
from127.0.0.1:3000
– Luca Kiebel
Nov 19 '18 at 10:24
You have to either add CORS support for socket.io or force the client to connect immediately with the webSocket transport (which is not subject to CORS) and not use the socket.io slow start using a couple web requests (which are subject to CORS).
– jfriend00
Nov 19 '18 at 10:26
1
Here's how to enable CORS for socket.io: socket.io cross origin blocked
– jfriend00
Nov 19 '18 at 10:27
Thank you for the help :)
– rolle
Nov 19 '18 at 10:43
I dunno I still can get it working it is throwing "Cross-Origin Request Blocked" I edited the post and have it all working on one port now. However still a no go when I upload to a server for testing :(
– rolle
Nov 20 '18 at 6:38