@@ -4,38 +4,36 @@ use Mojo::Base 'Mojolicious', -signatures;
44use Mojo::File qw( curfile path) ;
55use YAML::XS qw/ LoadFile/ ;
66
7- BEGIN {
8- use Env qw( WW3_ROOT) ;
9- $WW3_ROOT = curfile-> dirname-> dirname-> to_string;
10- }
11-
127use DB::Schema;
138use WeBWorK3::Hooks;
149
1510my $perm_table ;
1611
1712# This method will run once at server start
1813sub startup ($self ) {
19- # log to file if we're in production mode
14+ # Pick the config file to use and set up logging dependant on the mode being run in.
15+ my $config_file ;
2016 if ($ENV {MOJO_MODE } && $ENV {MOJO_MODE } eq ' production' ) {
21- my $path = path(" $ENV {WW3_ROOT}/logs" )-> make_path-> child(' webwork3.log' );
22- $self -> log -> path($path );
23- }
17+ $self -> log -> path($self -> home-> child(' logs' , ' webwork3.log' ));
2418
25- my $config ;
26-
27- if ($ENV {MOJO_MODE } && $ENV {MOJO_MODE } eq ' test' ) {
28- my $path = path(" $ENV {WW3_ROOT}/logs" )-> make_path-> child(' webwork3_test.log' );
29- $self -> log -> path($path );
19+ $config_file = $self -> home-> child(' conf' , ' webwork3.yml' );
20+ $config_file = $self -> home-> child(' conf' , ' webwork3.dist.yml' ) unless -e $config_file ;
21+ } elsif ($ENV {MOJO_MODE } && $ENV {MOJO_MODE } eq ' test' ) {
22+ $self -> log -> path($self -> home-> child(' logs' , ' webwork3_test.log' ));
3023 $self -> log -> level(' trace' );
31- my $test_config_file = " $ENV {WW3_ROOT}/conf/ww3-dev.yml" ;
32- $test_config_file = " $ENV {WW3_ROOT}/conf/ww3-dev.dist.yml" unless (-e $test_config_file );
33- $config = $self -> plugin(NotYAMLConfig => { file => $test_config_file });
24+
25+ $config_file = $self -> home-> child(' conf' , ' webwork3-test.yml' );
26+ $config_file = $self -> home-> child(' conf' , ' webwork3-test.dist.yml' ) unless -e $config_file ;
27+ $self -> plugin(NotYAMLConfig => { file => $config_file });
3428 } else {
35- # Load configuration from config file
36- $config = $self -> plugin(' NotYAMLConfig' );
29+ $config_file = $self -> home-> child(' conf' , ' webwork3-dev.yml' );
30+ $config_file = $self -> home-> child(' conf' , ' webwork3.yml' ) unless -e $config_file ;
31+ $config_file = $self -> home-> child(' conf' , ' webwork3.dist.yml' ) unless -e $config_file ;
3732 }
3833
34+ # Load configuration from config file
35+ my $config = $self -> plugin(NotYAMLConfig => { file => $config_file });
36+
3937 # Configure the application
4038 $self -> secrets($config -> {secrets });
4139
@@ -65,7 +63,7 @@ sub startup ($self) {
6563 $self -> sessions-> secure($config -> {cookie_secure });
6664
6765 # Load permissions and set up a helper for dealing with permissions.
68- $perm_table = LoadFile(" $ENV {WW3_ROOT}/ conf/ permissions.yaml" );
66+ $perm_table = LoadFile($self -> home -> child( ' conf' , ' permissions.yaml' ) );
6967 $self -> helper(perm_table => sub ($c ) { return $perm_table ; });
7068
7169 # Handle all api route exceptions
0 commit comments