我的Mercure应用程序有问题,
我通过修理厂运行-合成美尔库尔的形象:
version: '3.7'
networks:
default:
external:
name: localdev
services:
mercure:
image: dunglas/mercure
environment:
DEBUG: "debug"
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
# In the cors_origin, add your domain(s). Or just use *
MERCURE_EXTRA_DIRECTIVES: |-
cors_origins https://localhost
ports:
- 1337:80
- 1338:443在具有MERCURE_PUBLISHER_JWY_KEY和订阅密钥im的部分,默认情况下将其设置为!ChangeMe!,并且它按其应有的方式工作。
const url = new URL(
"https://localhost/.well-known/mercure"
);
url.searchParams.append("topic", "chat");
const eventSource = new EventSource(url, {
headers: {
mercureAuthorization: 'Bearer (secret token)',
},
});
eventSource.onmessage = (event) => {
this.$notify({
type: "success",
text: "push",
});
console.log(event);
};
},我在Vue的订阅者正在工作,而JWT的签名部分是!ChangeMe!,例如:

但是我想让它变得安全,所以我想把它改成更长更难猜的东西。但是,当im将其更改为某种哈希时,我的订阅服务器就无法工作,并得到401个未经授权的错误。但是,当im通过邮递员推送数据时,我会得到响应和uuid。
邮递员响应新的jwt_key:

使用新jwt_key的Vue响应:

发布于 2022-06-24 09:56:21
我解决了我的问题。原因是在EventSource中没有传递auth头,我已经添加了这填充,现在它可以工作了!
https://stackoverflow.com/questions/72730015
复制相似问题