[2077] | 1 | package ProjectBuilder;
|
---|
| 2 | use Mojo::Base 'Mojolicious';
|
---|
| 3 | use ProjectBuilder::Model::Confs;
|
---|
[2624] | 4 | use Data::Dumper;
|
---|
| 5 | use ProjectBuilder::YAML;
|
---|
| 6 | use JSON;
|
---|
[2077] | 7 |
|
---|
[2624] | 8 | # This method will run once at server start
|
---|
[2077] | 9 | sub startup {
|
---|
| 10 | my $self = shift;
|
---|
| 11 |
|
---|
[2624] | 12 | print Dumper($self);
|
---|
[2077] | 13 | # Model
|
---|
| 14 | $self->helper(confs => sub { state $confs = ProjectBuilder::Model::Confs->new() });
|
---|
| 15 |
|
---|
[2624] | 16 | # Load configuration from hash returned by config file - doesn't work for now
|
---|
| 17 | #my $config = $self->plugin('Config' => { file => 'etc/pb-server.json' });
|
---|
[2077] | 18 |
|
---|
[2624] | 19 | # Configure the application
|
---|
| 20 | #$self->secrets([split /:/, $ENV{'BLOG_SECRETS'} || 'super:s3cret']);
|
---|
| 21 | #$self->secrets($config->{secrets});
|
---|
| 22 |
|
---|
| 23 | # Load Open API endpoins
|
---|
[2077] | 24 | # /api * api
|
---|
| 25 | # +/confs POST "store"
|
---|
| 26 | # +/confs GET "list"
|
---|
| 27 | # +/confs/(:id) PUT "update"
|
---|
| 28 | # +/confs/(:id) DELETE "remove"
|
---|
| 29 | # +/confs/(:id) GET "show"
|
---|
[2624] | 30 | my $c = {
|
---|
| 31 | #schema => "v3",
|
---|
| 32 | default_response_codes => [400, 401, 404, 500, 501],
|
---|
| 33 | #default_response_name => 1,
|
---|
| 34 | url => 'file:///usr/share/pb/api.yaml',
|
---|
| 35 | };
|
---|
| 36 | $self->plugin(OpenAPI => $c);
|
---|
| 37 | print "After Plugin OpenAPI\n";
|
---|
| 38 | #$self->plugin(OpenAPI => {schema_file => $self->home->rel_file('api.yaml'), schema => "v3"});
|
---|
[2077] | 39 |
|
---|
| 40 | # Regular web pages
|
---|
| 41 | # / GET
|
---|
| 42 | # /confs GET confs
|
---|
| 43 | # /confs/create GET "create_conf"
|
---|
| 44 | # /confs POST "store_conf"
|
---|
| 45 | # /confs/:id GET "show_conf"
|
---|
| 46 | # /confs/:id/edit GET "edit_conf"
|
---|
| 47 | # /confs/:id PUT "update_conf"
|
---|
| 48 | # /confs/:id DELETE "remove_conf"
|
---|
[2624] | 49 |
|
---|
| 50 | # Router
|
---|
[2077] | 51 | my $r = $self->routes;
|
---|
[2624] | 52 |
|
---|
| 53 | # Normal route to controller
|
---|
| 54 | $r->get('/w')->to('example#welcome');
|
---|
[2077] | 55 | $r->get('/' => sub { shift->redirect_to('confs') });
|
---|
| 56 | $r->get('/confs')->to('conf#list');
|
---|
| 57 | $r->get('/confs/create')->to('conf#create')->name('create_conf');
|
---|
| 58 | $r->post('/confs')->to('conf#store')->name('store_conf');
|
---|
| 59 | $r->get('/confs/:id')->to('conf#show')->name('show_conf');
|
---|
| 60 | $r->get('/confs/:id/edit')->to('conf#edit')->name('edit_conf');
|
---|
| 61 | $r->put('/confs/:id')->to('conf#update')->name('update_conf');
|
---|
| 62 | $r->delete('/conconfid')->to('conf#remove')->name('remove_conf');
|
---|
| 63 |
|
---|
[2461] | 64 | # Swagger2 module not maintained anymore
|
---|
| 65 | #require Swagger2::Editor;
|
---|
[2624] | 66 | #my $editor = Swagger2::Editor->new(specification_file => $self->home->rel_file('api.yaml'));
|
---|
[2461] | 67 | #$r->route('/editor')->detour(app => $editor);
|
---|
[2077] | 68 | }
|
---|
| 69 |
|
---|
| 70 | 1;
|
---|