node.js - SSL:Heroku、Nodejs、Socketio、ReactJS

标签 node.js ssl heroku socket.io reactjs

我正在将应用程序部署到 Heroku poke-chat ,一切都很好,应该是实时的,但是如果你看到控制台不工作,我得到这个错误

Mixed Content: The page at 'https://poke-chat.herokuapp.com/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1441366303148-19'. This request has been blocked; the content must be served over HTTPS

我也不知道为什么:c

这是我的 index.js

import express from 'express';
import http from 'http';
import engine from 'socket.io';
import dbapi from './db-api';

const port = process.env.PORT || 3000;
const app = express();

//Ruta de archivos estaticos

app.use('/', express.static(__dirname + '/public'));

app.get('/pokemons', (req, res) => {
    dbapi.pokemons.find((pokemons) => {
        res.json(pokemons);
    })
});

app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html');
});

let server = http.createServer(app).listen(port, () => {
    console.log(`El servidor esta escuchando en el puerto ${port}`);
});

const io = engine.listen(server);

io.on('connection', (socket) => {
    socket.on('message', (msg) => {
        io.emit('message', msg);
    })
})

谢谢你的帮助:P

最佳答案

问题

这是服务器端代码,看起来不错。

问题似乎出在客户端代码上,您似乎在其中请求

http://localhost:3000/socket.io/?EIO=3&transport=polling&t=1441366303148-19

解决方案:

将域更改为指向 https://poke-chat.herokuapp.com/ 而不是 http://localhost:3000

希望对你有帮助

关于node.js - SSL:Heroku、Nodejs、Socketio、ReactJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32397131/

相关文章:

node.js - 在不同于 .net 的 Node 中创建的安全 token

.htaccess - 如何将所有网站请求重定向到没有 www 的 HTTPS

PHP CURL 很少出现 SSL 连接错误

node.js - Sequelize 给出 TypeError

node.js - 在heroku上部署typescript应用程序,执行错误

javascript - 无法使用 NodeJs 加载样式表或 js 文件

javascript - 如何设置Angular 2.0的环境?

ssl - 使用站点范围的 ssl 我真的需要加密明文 paypal 按钮吗?

node.js - Google Cloud PubSub - 似乎无法获取主题

javascript - 两个字符串在 node js 中不相等,但对我来说看起来相等