Skip to content

Commit 0bd1c6f

Browse files
committed
added cookbook recipe
1 parent 5ef4903 commit 0bd1c6f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/Mojolicious/Guides/Cookbook.pod

+22
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,28 @@ requests.
177177
if $self->req->headers->header('X-Forwarded-Protocol') eq 'https';
178178
});
179179

180+
=head2 Embedding
181+
182+
You can also use the builtin web server to embed L<Mojolicious> applications
183+
into alien environments like foreign event loops.
184+
185+
use Mojolicious::Lite;
186+
use Mojo::Server::Daemon;
187+
188+
# Normal action
189+
get '/' => sub {
190+
my $self = shift;
191+
$self->render(text => 'Hello World!');
192+
};
193+
194+
# Connect application with custom daemon
195+
my $daemon =
196+
Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
197+
$daemon->prepare_ioloop;
198+
199+
# Call "one_tick" repeatedly from the alien environment
200+
$daemon->ioloop->one_tick while 1;
201+
180202
=head1 USER AGENT
181203

182204
When we say L<Mojolicious> is a web framework we actually mean it.

0 commit comments

Comments
 (0)