You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5 KiB

10 years ago
package LDV;
use strict;
use warnings;
use utf8;
use Mojo::Base 'Mojolicious';
sub startup {
my ($self) = @_;
my $config = $self->app->home->rel_file('conf/ldv.conf');
$self->plugin(Config => {file => $config});
9 years ago
$self->plugin(I18N => {default => 'ru'});
$self->plugin('LDV::Helpers');
10 years ago
$self->app->mode('production');
$self->app->secrets([ $self->app->config->{secret} ]);
10 years ago
$self->app->attr(json => sub {
require JSON;
my $json = JSON->new->utf8;
return $json;
});
$self->app->attr(email => sub {
require LDV::Email;
my $email = LDV::Email->new($self->app->config->{email} // {});
return $email;
});
$self->app->attr(ldap => sub {
require LDV::LDAP;
my $ldap = LDV::LDAP->new($self->app->config->{ldap});
return $ldap;
});
7 years ago
$self->app->attr(db => sub {
require LDV::DB;
my $db = LDV::DB->new($self->app->config->{db});
$db->connect;
return $db;
});
my $loop = Mojo::IOLoop->singleton;
$loop->recurring(60 => sub {
$self->app->db->ping;
$self->app->log->debug("db ping, process $$");
});
7 years ago
10 years ago
my $r = $self->routes;
{ # /user
10 years ago
my $user = $r->route('/user') -> to(controller => 'user');
$user->get('/') ->to(cb => sub { shift->redirect_to('/user/login'); });
$user->get('/login') ->to(action => 'login');
$user->get('/register') ->to(action => 'register');
$user->get('/profile') ->to(action => 'profile');
10 years ago
10 years ago
$user->post('/auth') ->to(action => 'auth');
$user->get ('/logout') ->to(action => 'logout');
$user->post('/create') ->to(action => 'create');
$user->post('/update') ->to(action => 'update');
7 years ago
$user->get('/eaccess') ->to(action => 'eaccess');
}
10 years ago
10 years ago
{ # /zerobin
my $zb = $r->route('/zerobin') -> to(controller => 'zerobin');
10 years ago
$zb->post('/') -> to(action => 'save');
$zb->get ('/') -> to(action => 'create');
$zb->route('/:time', time => qr/\d+/)
->via('GET') -> to(action => 'view');
$zb->get('/prune') -> to(action => 'prune');
10 years ago
}
7 years ago
{ # /filebin
my $conf = $self->app->config->{filebin};
my $fb = $r->route('/filebin') -> to(controller => 'filebin');
$fb->post('/') -> to(action => 'save');
$fb->get ('/') -> to(action => 'create');
$fb->route('/:time', time => qr/\d+/)
10 years ago
->via('GET') -> to(action => 'view');
7 years ago
$fb->get ('/prune') -> to(action => 'prune');
$fb->get ('/latest') -> to(action => 'latest')
if $conf->{show_latest};
10 years ago
mkdir $self->app->home->child('public', 'files');
7 years ago
$ENV{MOJO_MAX_MESSAGE_SIZE} = $conf->{file_maxsize} + 2 * 1024 * 1024; # +2Mb
10 years ago
}
10 years ago
}
1;