blib/lib/Daje.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Daje;
2 1 ▶use Mojo::Base 'Mojolicious', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # NAME
5 # ====
6 #
7 # Daje - is a Mojolicious server serving Daje stuff
8 #
9 #
10 #
11 # SYNOPSIS
12 # ========
13 #
14 # use Daje;
15 #
16 # DESCRIPTION
17 # ===========
18 #
19 # Daje is a web server
20 #
21 #
22 # LICENSE
23 # =======
24 #
25 # Copyright (C) janeskil1525.
26 #
27 # This library is free software; you can redistribute it and/or modify
28 # it under the same terms as Perl itself.
29 #
30 # AUTHOR
31 # ======
32 #
33 # janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
34 #
35 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 0 ▶use Mojo::Pg;
Subroutine BEGIN: called CC=1 SCAR=2.6
37  
38 our $VERSION = "0.30";
39 # $ENV{DAJE_HOME} = '/home/jan/Project/Daje/'
40 # unless $ENV{DAJE_HOME};
41  
42 has home => sub {
43 Mojo::Home->new(cwd);
44 };
45  
46 has 'auth';
47 has 'secrets';
48  
49 # This method will run once at server start
50 sub startup ($self) {
51  
52 # Load configuration from config file
53 my $logfile = $self->home() . "/../config/config.conf";
54  
55 my $config = $self->plugin('Config',{file => $logfile});
56 $self->log->path($self->home() . $self->config('log'));
57 $self->log->level($self->config('loglevel'));
58  
59 $self->log->debug("Test");
60 $self->helper(pg => sub {state $pg = Mojo::Pg->new->dsn(shift->config('pg'))});
61 say $self->pg->db->query('select version() as version')->hash->{version};
62 $self->log->debug($self->pg->db->query('select version() as version')->hash->{version});
63 $self->plugin('Minion' => { Pg => $self->pg });
64  
65  
66 my $r = $self->routes;
67 say "Daje " . $self->config->{project};
68 my $auth = $r->under($self->config->{project} . '/api/' => sub ($c) {
69 # say "authentichate " . $c->req->headers->header('X-Token-Check');
70 # Authenticated
71 say "Auth started";
72 return 1 if $c->login->authenticate($c->req->headers->header('X-Token-Check'));
73 # Not authenticated
74 $c->render(json => '{"error":"unknown error"}');
75 say "Auth failed";
76 return undef;
77 });
78  
79 $self->auth($auth);
80 $self->plugin('Daje::Plugin::Apploader' => { pg => $self->pg });
81 # Configure the application
82 $self->app->jwt->secret(@{$config->{secrets}}[0]);
83  
84 $self->secrets($config->{secrets});
85  
86 }
87  
88 1;
89  
90  
91 #################### pod generated by Pod::Autopod - keep this line to make pod updates possible ####################
92  
93 =head1 NAME
94  
95  
96 Daje - is a Mojolicious server serving Daje stuff
97  
98  
99  
100  
101  
102 =head1 SYNOPSIS
103  
104  
105 use Daje;
106  
107  
108  
109 =head1 DESCRIPTION
110  
111  
112 Daje is a web server
113  
114  
115  
116  
117 =head1 REQUIRES
118  
119 L<Mojo::Pg>
120  
121 L<Cwd>
122  
123 L<Mojo::Base>
124  
125  
126 =head1 METHODS
127  
128 =head2 startup
129  
130 startup();
131  
132 This method will run once at server start
133  
134  
135  
136 =head1 AUTHOR
137  
138  
139 janeskil1525 E<lt>janeskil1525@gmail.comE<gt>
140  
141  
142  
143 =head1 LICENSE
144  
145  
146 Copyright (C) janeskil1525.
147  
148 This library is free software; you can redistribute it and/or modify
149 it under the same terms as Perl itself.
150  
151  
152  
153 =cut
154  
↑ Summary