Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

node.js - Failed to load resource: net::ERR_INSECURE_RESPONSE socket.io

I am connecting to a port on my server via ssl... recently i have started to get Failed to load resource: net::ERR_INSECURE_RESPONSE error on chrome while connecting to the node.js+socket.io server.Here is my server setting up code:

var fs = require('fs');
var express = require('express');
var routes = require('./routes');
var https = require('https');
var path = require('path');
var socketio = require('socket.io');
var util = require('util');
var url = require('url');
var privateKey  =  fs.readFileSync('ssl/keys/xxxxxxxxxxxxxxxxxxxxxxxx.key', 'utf8');
var certificate = fs.readFileSync('ssl/certs/xxxxxxxxxxxxxx.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var sizeOf = require('image-size');


var DBWrapper = require('node-dbi').DBWrapper; 
var DBExpr = require('node-dbi').DBExpr; 
var dbConnectionConfig = { host: 'localhost', user: 'user', password: 'password', database: 'dbname' };
dbWrapper = new DBWrapper( "pg", dbConnectionConfig );
dbWrapper.connect();

var app = express();

app.set('port', process.env.PORT || 8080);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', routes.index);


var server = https.createServer(credentials,app).listen(app.get('port'), function(){
  console.log("Express server listening on port with https " + app.get('port'));
});

 var io = socketio.listen(server);

What am i doing wrong?

Edit: This is how i connect on client side:

socket = io.connect("https://website.com:8080", {'reconnect': false});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your certificate is probably self-signed.

Chromium block this kind of insecure content. If you are alone to use it as testing for example, you can just unblock it opening a new tab in Google chrome and going to https://example.com:8080. Chrome will advertise you that the resource use a self-signed SSL certificate and ask you if you want to continue. If you do, your app will now work on your first tab.

Remember that you will do it for each navigation session in chrome.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...