source: ProjectBuilder/devel/pb-server/lib/ProjectBuilder.pm@ 2624

Last change on this file since 2624 was 2624, checked in by Bruno Cornec, 4 years ago

More tests around OpenAPI - back to a working server with v3

File size: 2.3 KB
Line 
1package ProjectBuilder;
2use Mojo::Base 'Mojolicious';
3use ProjectBuilder::Model::Confs;
4use Data::Dumper;
5use ProjectBuilder::YAML;
6use JSON;
7
8# This method will run once at server start
9sub startup {
10 my $self = shift;
11
12 print Dumper($self);
13 # Model
14 $self->helper(confs => sub { state $confs = ProjectBuilder::Model::Confs->new() });
15
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' });
18
19 # Configure the application
20 #$self->secrets([split /:/, $ENV{'BLOG_SECRETS'} || 'super:s3cret']);
21 #$self->secrets($config->{secrets});
22
23 # Load Open API endpoins
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"
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"});
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"
49
50 # Router
51 my $r = $self->routes;
52
53 # Normal route to controller
54 $r->get('/w')->to('example#welcome');
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
64 # Swagger2 module not maintained anymore
65 #require Swagger2::Editor;
66 #my $editor = Swagger2::Editor->new(specification_file => $self->home->rel_file('api.yaml'));
67 #$r->route('/editor')->detour(app => $editor);
68}
69
701;
Note: See TracBrowser for help on using the repository browser.