示例 ws 不适用于带有 Mojo 的 https



Uncaught DOMException: The operation is insecure.

我在firefox中运行示例代码时得到了这个:

$ MOJO_LISTEN=http://*:5000 morbo index.pl             
use Mojolicious::Lite -signatures;
# Render template "index.html.ep" from the DATA section
get '/' => sub ($c) {
  $c->render(template => 'index');
};
# WebSocket service used by the template to extract the title from a web site
websocket '/title' => sub ($c) {
  $c->on(message => sub ($c, $msg) {
    my $title = $c->ua->get($msg)->result->dom->at('title')->text;
    $c->send($title);
  });
};
app->start;
__DATA__
@@ index.html.ep
% my $url = url_for 'title';
<script>
  const ws = new WebSocket('<%= $url->to_abs %>');
  ws.onmessage = function (event) { document.body.innerHTML += event.data };
  ws.onopen    = function (event) { ws.send('https://mojolicious.org') };
</script>

我在mojo前面使用了nginx代理,但网络套接字应该是wss,我认为

我不得不将这个env变量添加到命令行:

MOJO_LISTEN=http://*:5000 MOJO_REVERSE_PROXY=1 morbo index.pl

https://docs.mojolicious.org/Mojolicious/Guides/Cookbook#Reverse-代理

相关内容

  • 没有找到相关文章

最新更新