tpsgi 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env starman
  2. #pacakge bin::tpsgi;
  3. #ABSTRACT: PSGI application which simplifies migrating legacy/cgi applications to PSGI
  4. use strict;
  5. use warnings;
  6. use FindBin::libs;
  7. use TPSGI;
  8. my %options = main(@ARGV);
  9. =head1 USAGE
  10. tpsgi ... starman options
  11. tpsgi obeys a config file, ~/.tpsgi.ini which is in Config::Simple (key=value) format, with the keys being:
  12. verbose # Whether to print all log messages or not
  13. custom_log # Custom location for default (rotated) log
  14. routers # Router module(s), separate with comma
  15. indices # Dirindex files. In addition to index.html, index.htm, index.cgi
  16. loggers # Logger module(s), separate with comma
  17. auth # Authentication module
  18. domain # Domain name of the application, used by things like service files
  19. basedir # Directory you want to base this out of (defaults to HOME).
  20. user # Who to run as
  21. The idea is that this application is going to be run in a chroot with the user's homedir being the application dir.
  22. =cut
  23. sub main {
  24. my (@args) = @_;
  25. my %options = TPSGI::get_config();
  26. return %options;
  27. }
  28. our $app = sub {
  29. $options{verbose} = 1;
  30. # Change your dir into whatever basedir you need to be in
  31. chdir($options{'basedir'}) or warn "Can't chdir into $options{'basedir'}: $!";
  32. my $self = TPSGI->new(%options);
  33. return eval { $self->app(@_) } || do {
  34. my $env = shift;
  35. $env->{'psgi.errors'}->print($@);
  36. # Redact the stack trace past line 1, it usually has things which should not be shown
  37. $self->{cur_query}->{message} = $@;
  38. $self->{cur_query}->{message} =~ s/\n.*//g if $self->{cur_query}->{message};
  39. return $self->error($self->{cur_query});
  40. };
  41. };