地平线连接到现有的 express js 应用程序导致 400 错误请求
horizion connect to an existing expressjs app results in 400 bad request
我尝试通过 horizon 从我的 html 页面连接到我的 expressjs 应用程序。
我的服务器是这样的[https://github.com/rethinkdb/horizon/blob/next/examples/express-server/main.js]:
#!/usr/bin/env node
'use strict'
const express = require('express');
const horizon = require('@horizon/server');
const app = express();
const http_server = app.listen(8181);
const options = { auth: { token_secret: 'my_super_secret_secret' } };
const horizon_server = horizon(http_server, options);
app.use(express.static('public'));
console.log('Listening on port 8181.');
然后我关注了这个link:http://horizon.io/docs/getting-started/#integrating-horizon-with-an-existing-application
并创建了以下 html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://localhost:8181/horizon/horizon.js"></script>
<script>
var horizon = Horizon({host: 'localhost:8181'});
horizon.onReady(function() {
document.querySelector('h1').innerHTML = 'App works!'
});
horizon.connect();
</script>
</head>
<body>
<marquee><h1></h1></marquee>
</body>
</html>
我的 package.json 依赖项:
"dependencies": {
"@horizon/server": "^1.0.3",
"express": "^4.13.4",
"horizon": "^1.0.3"
}
它导致 400 错误:
polling-xhr.js:250GET http://localhost:8181/horizon/?EIO=3&transport=polling&t=LJke5oP 400(错误请求)
index.js:66收到错误:错误:Websocket ws://localhost:8181 遇到错误
怎么了,我如何获得到我的 express 后端的有效连接?
我看到这个 但我不知道它是否是同一个问题。
更新
我创建了一个 repository for my question and asked the same question on the projectpage.
信息:似乎是 bug,应该会在下一个版本中修复。
我尝试通过 horizon 从我的 html 页面连接到我的 expressjs 应用程序。
我的服务器是这样的[https://github.com/rethinkdb/horizon/blob/next/examples/express-server/main.js]:
#!/usr/bin/env node
'use strict'
const express = require('express');
const horizon = require('@horizon/server');
const app = express();
const http_server = app.listen(8181);
const options = { auth: { token_secret: 'my_super_secret_secret' } };
const horizon_server = horizon(http_server, options);
app.use(express.static('public'));
console.log('Listening on port 8181.');
然后我关注了这个link:http://horizon.io/docs/getting-started/#integrating-horizon-with-an-existing-application 并创建了以下 html:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://localhost:8181/horizon/horizon.js"></script>
<script>
var horizon = Horizon({host: 'localhost:8181'});
horizon.onReady(function() {
document.querySelector('h1').innerHTML = 'App works!'
});
horizon.connect();
</script>
</head>
<body>
<marquee><h1></h1></marquee>
</body>
</html>
我的 package.json 依赖项:
"dependencies": {
"@horizon/server": "^1.0.3",
"express": "^4.13.4",
"horizon": "^1.0.3"
}
它导致 400 错误:
polling-xhr.js:250GET http://localhost:8181/horizon/?EIO=3&transport=polling&t=LJke5oP 400(错误请求)
index.js:66收到错误:错误:Websocket ws://localhost:8181 遇到错误
怎么了,我如何获得到我的 express 后端的有效连接?
我看到这个
更新 我创建了一个 repository for my question and asked the same question on the projectpage.
信息:似乎是 bug,应该会在下一个版本中修复。