我有一个使用featherjs制作的应用程序,我希望能够通过https运行。我已经实现了这个目标。我是通过将'index.js'文件更改为以下内容来实现的:
const fs = require('fs');
const https = require('https');
const app = require('./app');
const port = app.get('port');
const host = app.get('host');
//const server = app.listen(port);
const server = https.createServer({
key: fs.readFileSync('./certs/aex007.key'),
cert: fs.readFileSync('./certs/aex007.crt')
}, app).listen(port, function(){
console.log("Mfp Backend started: https://" + host + ":" + port);
});
当我在postman中访问例如'https://127.0.0.1/a_service_name'时,接受证书后即可获得结果。当我在浏览器中访问该地址时也能得到结果,但由于证书是自签名的,因此会显示'红色'证书提示。
所以我的问题是:当我在浏览器中访问'http://127.0.01'时,与其获取'socket'信息的'index.html'文件,我只得到了一个空白页面。在控制台中出现以下错误:
目前我使用的'index.html'文件内容如下:info: (404) Route: /socket.io/?EIO=3&transport=polling&t=LwydYAw - Page not found
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script type="text/javascript" src="//cdn.rawgit.com/feathersjs/feathers-client/v1.1.0/dist/feathers.js"></script>
<script type="text/javascript">
var socket = io('https://127.0.0.1:3001');
var client = feathers()
.configure(feathers.hooks())
.configure(feathers.socketio(socket));
var todoService = client.service('/some_service');
todoService.on('created', function(todo) {
alert('created');
console.log('Someone created a todo', todo);
});
</script>
请问如何获取警报信息?
编辑于2017/09/27 我在网上发现socket.io的配置如下:
var https = require('https'),
fs = require('fs');
var options = {
key: fs.readFileSync('ssl/server.key'),
cert: fs.readFileSync('ssl/server.crt'),
ca: fs.readFileSync('ssl/ca.crt')
};
var app = https.createServer(options);
io = require('socket.io').listen(app); //socket.io server listens to https connections
app.listen(8895, "0.0.0.0");
但是,feathers-socket.io 的 require 是在 app.js 中而不是 index.js 中。我想知道我能否移动它?