#!/usr/bin/env perl
use Mojolicious::Lite;
use feature 'say';
my $clients = {};
my $curr_msg = {};
post '/' => sub {
my $self = shift;
my $params = $self->req->params->names;
for (@$params) {
$curr_msg->{$_} = $self->param($_);
};
$self->render(json => { status => 'post ok', data => $curr_msg});
};
websocket '/ws' => sub {
my $self = shift;
app->log->debug(sprintf 'Client connected: %s', $self->tx);
my $id = sprintf "%s", $self->tx;
$clients->{$id} = $self->tx;
if (%$curr_msg) {
for (keys %$clients) {
$clients->{$_}->send(json => $curr_msg);
};
$curr_msg = {};
};
$self->on(finish => sub {
app->log->debug('Client disconnected');
delete $clients->{$id};
});
};
app->start;
Could you please also explain, what do I need to store in database (pub/sub backend like PostgreSQL or Redis) in case of scalable solution?