Dancer2-Plugin-WebService

 view release on metacpan or  search on metacpan

CREATE_SAMPLE_APPLICATION  view on Meta::CPAN

As an example lets create the "TestService" application
We need a non-privileged user e.g dancer

  sudo -u dancer dancer2 gen --application TestService --directory TestService --path /home/dancer --overwrite

  [ -d /var/lib/WebService/TestService ] || /usr/bin/mkdir -p /var/lib/WebService/TestService
  [ -d /var/log/WebService ]             || /usr/bin/mkdir    /var/log/WebService
  cp /home/dancer/TestService/environments/production.yml     /home/dancer/TestService/environments/production.yml.orig
  cp /home/dancer/TestService/environments/development.yml    /home/dancer/TestService/environments/development.yml.orig
  cp /home/dancer/TestService/config.yml                      /home/dancer/TestService/config.yml.orig
  /usr/bin/chown -R dancer:dancer /var/lib/WebService/TestService /home/dancer/TestService /var/log/WebService

The custom routes with your code are stored at the file /home/dancer/TestService/lib/TestService.pm

Configure the firewall to listen e.g at port 3000

  # Redhat
  firewall-cmd --zone=public --permanent --add-port=3000/tcp
  firewall-cmd --reload
  firewall-cmd --list-all

Optional compress the http traffic if you have fast CPU and large replies.
vi /home/dancer/TestService/bin/app.psgi

  #!/usr/bin/perl
  use strict;
  use warnings;
  use FindBin;
  use lib "$FindBin::Bin/../lib";
  use TestService;
  use Plack::Builder;
  builder {
  enable 'Deflater';
  # you can have multiple applications on different http paths
  mount '/' => TestService->to_app
  }

Configure the production enviroment at
/home/dancer/TestService/environments/production.yml

  logger           : file     # console: to STDOUT , file: to file
  log              : error    # core, debug, info, warning, error
  warnings         : 1        # should Dancer2 consider warnings as critical errors?
  show_errors      : 1        # if true shows a detailed debug error page , otherse the views/404.tt or public/404.html
  startup_info     : 1        # print the banner
  no_server_tokens : 1        # disable server tokens in production environments
  show_stacktrace  : 0
  engines          :
    logger         :
      console      :
        log_format : '{"ts":"%T","host":"%h","pid":"%P","message":"%m"}'
      file         :
        log_format : '{"ts":"%{%Y-%m-%d %H:%M:%S}t","host":"%h","level":"%L","message":"%m"}'
        log_dir    : "/var/log/WebService"
        file_name  : "TestService.log"

Configure the development enviroment at
/home/dancer/TestService/environments/development.yml

  logger           : console
  log              : debug
  warnings         : 1
  show_errors      : 1
  startup_info     : 1
  show_stacktrace  : 1
  no_server_tokens : 0
  show_stacktrace  : 1
  engines          :
    logger         :
      console      :
        log_format : '{"ts":"%T","host":"%h","pid":"%P","message":"%m"}'



( run in 1.558 second using v1.01-cache-2.11-cpan-71847e10f99 )