gs;
our $VERSION = '0.16';
1;
__END__
=head1 NAME
Mojo::WebSocketProxy - WebSocket proxy for JSON-RPC 2.0 server
=head1 SYNOPSIS
# lib/your-application.pm
use parent 'Mojolicious';
f->plugin(
'web_socket_proxy' => {
actions => [
['json_key', {some_param => 'some_value'}]
],
base_path => '/api',
eb_socket_proxy' => {
actions => [
[
'json_key',
{
instead_of_forward => sub {
:WebSocketProxy::Backend::JSONRPC;
use strict;
use warnings;
use parent qw(Mojo::WebSocketProxy::Backend);
use feature qw(state);
no indirect;
use curry;
use MojoX::JSON::RPC::Client;
our $VERS
ister_type('jsonrpc');
sub url { return shift->{url} }
my $request_number = 0;
=head2 call_rpc
Description: Makes a remote call to a process returning the result to the client in JSON format.
B
s undef.
=cut
sub call_rpc {
my ($self, $c, $req_storage) = @_;
state $client = MojoX::JSON::RPC::Client->new;
my $url = $req_storage->{url} // $self->url;
die 'No url found' unles
'0.16'; ## VERSION
=head1 NAME
Log::Any::Adapter::DERIV - standardised logging to STDERR and JSON file
=head1 SYNOPSIS
use Mojo::WebSocketProxy::RequestLogger;
my $logger = Mojo::WebSocketProx
Abstract base class for RPC dispatch backends. See
L<Mojo::WebSocketProxy::Backend::JSONRPC> for the original JSON::RPC backend.
=cut
=head1 CLASS METHODS
=cut
=head2 register_type
$class->r
$args = $req_storage->{args};
if (ref $args ne 'HASH') {
# for invalid call, eg: not json
$req_storage->{args} = {};
$result = $c->wsp_error('error', 'BadRequest', 'The ap
END__
=head1 NAME
Mojo::WebSocketProxy::Parser
=head1 DESCRIPTION
This module using for parse JSON websocket messages.
=head1 METHODS
=head2 parse_req
=head1 SEE ALSO
L<Mojolicious::Plugin::We
qw($log);
# Other backend types may be available; we default to 'jsonrpc' in the code below
use Mojo::WebSocketProxy::Backend::JSONRPC;
our $VERSION = '0.16'; ## VERSION
sub register {
my (
my %args = %{$backend_configs->{$name}};
my $type = delete($args{type}) // 'jsonrpc';
my $key = $default_backend eq $name ? 'default' : $name;
$dispatche
to add a plain JSON::RPC backend
my $jsonrpc_backend_key = exists $dispatcher_config->{backends}->{default} ? 'http' : 'default';
$dispatcher_config->add_backend(
$jsonrpc_backend_key
jo::WebSocketProxy::Parser;
use Mojo::WebSocketProxy::Config;
use Class::Method::Modifiers;
use JSON::MaybeUTF8 qw(:v1);
use Log::Any qw($log);
use Unicode::Normalize ();
use Future::Mo
_response_size};
if ($max_response_size && length(encode_json_utf8($api_response)) > $max_response_size) {
$api_response->{json} = $c->wsp_error('error', 'ResponseTooLarge', 'Response too
nd_api_response = $config->{before_send_api_response};
$_->($c, $req_storage, $api_response->{json})
for grep { $_ } (ref $before_send_api_response eq 'ARRAY' ? @{$before_send_api_response