问题
I am using Pusher Channels
and delivering messages like in their tutorial:
https://pusher.com/docs/channels/getting_started/javascript
Client:
let pusher = new Pusher('APP_KEY', {
cluster: 'APP_CLUSTER'
});
let channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert('An event was triggered with message: ' + data.message);
});
Server:
// First, run 'npm install pusher'
var Pusher = require('pusher');
var pusher = new Pusher({
appId: 'APP_ID',
key: 'APP_KEY',
secret: 'APP_SECRET',
cluster: 'APP_CLUSTER'
});
pusher.trigger('my-channel', 'my-event', {"message": "hello world"});
Is there a way to secure the connection via port 443 on the IIS?
回答1:
To make sure Pusher Channels messages are sent from your server to Channels using HTTPS and then broadcast to Clients using WSS you need to the do the following:
For the nodejs library running on the server you need to set the option useTLS: true
var pusher = new Pusher({
appId: 'APP_ID',
key: 'APP_KEY',
secret: 'APP_SECRET',
cluster: 'APP_CLUSTER',
useTLS: true
});
https://github.com/pusher/pusher-http-node#configuration
For the pusher-js library running on the client you need to set the option forceTLS: true
let pusher = new Pusher('APP_KEY', {
cluster: 'APP_CLUSTER',
forceTLS: true
});
https://github.com/pusher/pusher-js#configuration
Finally to make sure that client connections are only accepted over a secure connection, you need to log into your Channels Dashboard account, find the app you need to secure, and click the App settings tab. Finally you need to tick the box "Force TLS" and click "Update" to apply settings. With this box ticked, client connections over port 80 will be rejected and the client will be forced to reconnect using a secure connection:
来源:https://stackoverflow.com/questions/57901908/securing-pushers-messages