Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using Mojolicious with NGINX Unit

by tbusch (Sexton)
on Feb 23, 2019 at 17:15 UTC ( [id://1230471]=perlquestion: print w/replies, xml ) Need Help??

tbusch has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get Mojolicious to work with NGINX Unit but I get the following error:
PSGI: Failed to run Perl Application: Undefined subroutine &main::1 called.
My Perl script is the following:
#!/usr/bin/perl use strict; use Mojolicious::Lite; get '/' => {text => 'Hello World'}; app->start;
and my NGINX unit config is:
{ "type": "perl", "processes": 5, "script": "/etc/unit/app.psgi", "environment": { "MOJO_MODE": "production" } }
Am I missing an environment variable ? It seems like Mojo is unable to detect in which environment it is. I have a similar setup for uWSGI where it works. Curiously the following script works in NGINX Unit:
#!/usr/bin/perl use strict; use warnings; use Plack::Builder; my $app = sub { my $env = shift; [200, [], ["Hello world from PSGI!\n"]]; }; builder { enable 'ContentLength'; $app; };
Any help or hint would be immensely appreciated.

Replies are listed 'Best First'.
Re: Using Mojolicious with NGINX Unit
by beech (Parson) on Feb 25, 2019 at 04:45 UTC
Re: Using Mojolicious with NGINX Unit
by tbusch (Sexton) on Feb 23, 2019 at 19:21 UTC
    I managed to eliminate the error by setting the env variable "PLACK_ENV" to anything which forces Mojolicious into PSGI mode, but Mojolicious seems to be hanging. Also I tested with Dancer2 and it works:
    #!/usr/bin/perl use Dancer2; use strict; get '/' => sub { "Hello World!" }; dance;

      Is 'sub' missing in get '/' => {text => 'Hello World'};?

      edit: Never mind that, it is actually ok. Got confused there for a moment looking at a different example:

      use Mojolicious::Lite; get '/' => sub { my $c = shift; $c->render(text => "OHAI!"); }; app->start;

      From this topic that talks about PSGI: here

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1230471]
Approved by Perlbotics
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found