The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Suffit::Server - The Suffit API web-server class

SYNOPSIS

    WWW::Suffit::Server;

DESCRIPTION

This module provides API web-server functionality

OPTIONS

    sub startup {
        my $self = shift->SUPER::startup( OPTION_NAME => VALUE, ... );

        # ...
    }

List of allowed options (pairs of name-value):

all_features

    all_features => 'on'

This option enables all of the init_* options, which are described bellow

Default: off

config_opts

    config_opts => { ... }

This option sets WWW::Suffit::Plugin::ConfigGeneral plugin options

Default:

    `noload => 1` if $self->configobj exists
    `defaults => $self->config` if $self->config is not void

init_authdb

    init_authdb => 'on'

This option enables AuthDB initialize

Default: off

init_api_routes

    init_api_routes => 'on'

Enable Suffit API routes

Default: off

init_rsa_keys

    init_rsa_keys => 'on'

This option enables RSA keys initialize

Default: off

syslog_opts

    syslog_opts => { ... }

This option sets WWW::Suffit::Plugin::Syslog plugin options

Default:

    `enable => 1` if the `Log` config directive is "syslog"

ATTRIBUTES

This class implements the following attributes

accepts

    accepts => 0,

Maximum number of connections a worker is allowed to accept, before stopping gracefully and then getting replaced with a newly started worker, passed along to "max_accepts" in Mojo::IOLoop

Default: 10000

See "accepts" in Mojo::Server::Prefork

cache

The WWW::Suffit::Cache object

clients

    clients => 0,

Maximum number of accepted connections this server is allowed to handle concurrently, before stopping to accept new incoming connections, passed along to "max_connections" in Mojo::IOLoop

Default: 1000

See "max_clients" in Mojo::Server::Daemon

configobj

The Config::General object or undef

acruxconfig

The Acrux::Config object or undef

datadir

    datadir => '/var/lib/myapp',

The sharedstate data directory (data dir)

Default: /var/lib/<MONIKER>

debugmode

    debugmode => 0,

If this attribute is enabled then this server is no daemonize performs

documentroot

    documentroot => '/var/www/myapp',

Document root directory

Default: /var/www/<MONIKER>

gid

    gid => 1000,
    gid => getgrnam( 'anonymous' ),

This attribute pass GID to set the real group identifier and the effective group identifier for this process

homedir

    homedir => '/usr/share/myapp',

The Project home directory

Default: /usr/share/<MONIKER>

logfile

    logfile => '/var/log/myapp.log',

The log file

Default: /var/log/<MONIKER>.log

loglevel

    loglevel => 'warn',

This attribute performs set the log level

Default: warn

max_history_size

    max_history_size => 25,

Maximum number of logged messages to store in "history"

Default: 25

moniker

    moniker => 'myapp',

Project name in lowercase notation, project nickname, moniker. This value often used as default filename for configuration files and the like

Default: decamelizing the application class

See "moniker" in Mojolicious

mysecret

    mysecret => 'dgdfg',

Default secret string

Default: <DEFAULT_SECRET>

no_daemonize

    no_daemonize => 1,

This attribute disables the daemonize process

Default: 0

pidfile

    pidfile => '/var/run/myapp.pid',

The pid file

Default: /tmp/prefork.pid

See "pid_file" in Mojo::Server::Prefork

project_name

    project_name => 'MyApp',

The project name. For example: MyApp

Default: current class name

private_key

    private_key => '...',

Private RSA key

project_version

    project_version => '0.01',

The project version. For example: 1.00

NOTE! This is required attribute!

public_key

    public_key => '...',

Public RSA key

requests

    requests => 0,

Maximum number of keep-alive requests per connection

Default: 100

See "max_requests" in Mojo::Server::Daemon

reload_sig

    reload_sig => 'USR2',
    reload_sig => 'HUP',

The signal name that will be used to receive reload commands from the system

Default: USR2

server_addr

    server_addr => '*',

Main listener address (host)

Default: * (::0, 0:0:0:0)

server_port

    server_port => 8080,

Main listener port

Default: 8080

server_url

    server_url => 'http://127.0.0.1:8080',

Main real listener URL

See ListenAddr and ListenPort configuration directives

Default: http://127.0.0.1:8080

spare

    spare => 0,

Temporarily spawn up to this number of additional workers if there is a need.

Default: 2

See "spare" in Mojo::Server::Prefork

tempdir

    tempdir => '/tmp/myapp',

The temp directory

Default: /tmp/<MONIKER>

trustedproxies

List of trusted proxies

Default: none

uid

    uid => 1000,
    uid => getpwnam( 'anonymous' ),

This attribute pass UID to set the real user identifier and the effective user identifier for this process

workers

    workers => 0,

Number of worker processes

Default: 4

See "workers" in Mojo::Server::Prefork

METHODS

This class inherits all methods from Mojolicious and implements the following new ones

listeners

This method returns server listeners as list of URLs

    $prefork->listen( $app->listeners );

preforked_run

    $app->preforked_run( COMMAND );
    $app->preforked_run( COMMAND, ...OPTIONS... );
    $app->preforked_run( COMMAND, { ...OPTIONS... } );
    $app->preforked_run( 'start' );
    $app->preforked_run( 'start', prerun => sub { ... } );
    $app->preforked_run( 'stop' );
    $app->preforked_run( 'restart', prerun => sub { ... } );
    $app->preforked_run( 'status' );
    $app->preforked_run( 'reload' );

This method runs your application using a command that is passed as the first argument

Options:

prerun
    prerun => sub {
        my ($app, $prefork) = @_;

        $prefork->on(finish => sub { # Finish
            my $this = shift; # Prefork object
            my $graceful = shift;
            $this->app->log->debug($graceful
                ? 'Graceful server shutdown'
                : 'Server shutdown'
            );
        });
    }

This option defines callback function that performs operations with prefork instance Mojo::Server::Prefork befor demonize and server running

raise

    $app->raise("Mask %s", "val");
    $app->raise("val");

Prints error message to STDERR and exit with errorlevel = 1

NOTE! For internal use only

reload

The reload hook

startup

Mojolicious application startup method

HELPERS

This class implements the following helpers

authdb

This is access method to the AuthDB object (state object)

jwt

This helper makes JWT object with RSA keys and returns it

token

This helper performs get of current token from HTTP Request headers

HISTORY

See Changes file

TO DO

See TODO file

SEE ALSO

Mojolicious, WWW::Suffit, WWW::Suffit::RSA, WWW::Suffit::JWT, WWW::Suffit::AuthDB

AUTHOR

Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>

COPYRIGHT

Copyright (C) 1998-2024 D&D Corporation. All Rights Reserved

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See LICENSE file and https://dev.perl.org/licenses/