配置Node.js应用程序以通过TCP以及AWS S3与Websockets一起使用 [英] Configuring a Node.js application to work with Websockets over TCP as well as AWS S3
问题描述
我正在开发Node.js应用程序,并安装WebSockets与ParseLiveQuery一起使用.为了使该应用程序完全运行,我需要对S3,图像等进行HTTPS访问,对WebSocket需要进行TCP访问.
I'm working on a Node.js application and installing WebSockets to use with ParseLiveQuery. For the app to work in full, I need HTTPS access for S3, images, etc. and TCP access for the WebSocket.
以下是我当前的设置:
还有我的index.js
文件
var S3Adapter = require('parse-server').S3Adapter;
var s3Adapter = new S3Adapter(
"myAppMediaServer",
{ directAccess: true,
baseUrl: 'http://myApp12345.cloudfront.net' // This could be your CloudFront URL
}
);
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://name:othername@ds55555-a0.mlab.com:9999,ds02222-a1.mlab.com:44444/appprod?replicaSet=rs-ds019322',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID,
masterKey: process.env.MASTER_KEY,
serverURL: process.env.SERVER_URL,
javascriptKey: process.env.JAVASCRIPT_KEY, vars
clientKey: process.env.CLIENT_KEY,
facebookAppIds: ['12345678'],
filesAdapter: s3Adapter,
verbose: process.env.VERBOSE_KEY || false,
allowClientClassCreation: process.env.CLIENT_CREATION || false,
liveQuery: {
classNames: ['GroupConvos', 'GroupMessages']
},
databaseOptions: { //defaults to 5 and caused bottlenecking issues
poolSize: 500
},
maxUploadSize: "5mb"
});
var app = express();
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);
我已经意识到我需要将443端口从TCP实例协议改回HTTPS,并且我对如何使其准确工作感到有些困惑,以便我的应用程序同时支持套接字的TCP和HTTPS对于其他一切.
I've been made aware that I need to change my 443 port back to HTTPS from a TCP instance protocol and I'm a bit confused about how to get this working precisely so that my app supports both TCP for sockets and HTTPS for everything else.
谢谢
修改
现在,我在端口80上有一个HTTP侦听器.听起来像我需要在443处创建另一个服务器,如下面的代码.那是第1步,对吧?
Right now I have an HTTP listener on port 80. It sounds like I need to create another server at 443 like the code below. That's step 1, right?
var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// new
var options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};
const https = require('https');
var httpsServer = https.createServer(options, app);
httpsServer.listen(443, function() {
console.log('ParseServer running on port 443 with SSL.');
});
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpsServer);
然后,AWS负载均衡器上允许HTTPS连接(以便S3文件获取/发布)工作的配置是什么?什么是安全的TCP配置(例如,我使用wss
来运行我的套接字?)? /p>
Then what is the configuration on my AWS load balancer to allow for HTTPS connections (so that S3 file get/post) works and what is the secure TCP configuration such that I'm using wss
to run my socket?
推荐答案
在一个简单的示例中,您需要执行以下操作.我正在展示我推荐的SSL证书的让我们加密"风格.我还建议今天只使用HTTPS,而根本不使用HTTP(或仅将HTTP重定向到HTTPS).
In a simple example you need to do something like this. I am showing the Let's Encrypt style of SSL certificates, which I do recommend. I also recommend just using HTTPS today and not using HTTP at all (or just redirect HTTP to HTTPS).
var https = require('https')
var options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};
var httpsServer = require('https').createServer(options,app);
httpsServer.listen(443, function() {
console.log('ParseServer running on port 443 with SSL.');
});
var parseLiveQueryServerSecure = ParseServer.createLiveQueryServer(httpsServer);
这篇关于配置Node.js应用程序以通过TCP以及AWS S3与Websockets一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!