Mojoliciousをどうしてもindex.cgiとして動かしたい

@nqounetです。

Mojoliciousで作っているアプリを、どうしてもindex.cgiで動かす必要があって、とりあえず、動くようになったのでメモしておきます。

index.cgi(昔は動いていた版)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/user/hoge/perl5/perlbrew/perls/perl-5.14.2/bin/perl
use utf8;

use lib 'lib';
use Mojo::Server::CGI;

$ENV{MOJO_APP}  = 'MyApp';
$ENV{MOJO_MODE} = 'production';

Mojo::Server::CGI->new->run;

1行目は、環境によって違いますが、Perlbrewを使っている場合はこんな感じだと思います。

で、久しぶりに動かしてみると、Your Mojo is working!としか出ないようになっていました。

どうしても、index.cgiとして動かしたかったのですが、どうも情報が少なくて調べてもよくわかりませんでした。

index.cgi(動いた版)

1
2
3
4
5
6
7
8
9
#!/user/hoge/perl5/perlbrew/perls/perl-5.14.2/bin/perl
use utf8;

use lib 'lib';

$ENV{MOJO_MODE} = 'production';

require Mojolicious::Commands;
Mojolicious::Commands->start_app('MyApp');

結果だけを見れば、シンプルになりました。 Mojolicious::Commandsが万能になって、起動スクリプトと同じように書けるようになったようです。

Perl鍋の報告も近々書きます。たぶん。

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy