Initial commit
This commit is contained in:
34
README.md
Normal file
34
README.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
## create a mojolicious app
|
||||||
|
|
||||||
|
### start a perl docker container
|
||||||
|
|
||||||
|
$ docker run --rm --init -it -v $PWD:/opt/app -p 3000:3000 -e USER_NAME=$(whoami) perl:threaded-trixie bash
|
||||||
|
|
||||||
|
### install mojolicious
|
||||||
|
|
||||||
|
# curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious
|
||||||
|
|
||||||
|
### create a user
|
||||||
|
|
||||||
|
# useradd -ms /bin/bash $USER_NAME
|
||||||
|
|
||||||
|
### switch to that user
|
||||||
|
|
||||||
|
# su - $USER_NAME
|
||||||
|
|
||||||
|
### switch to work dir
|
||||||
|
|
||||||
|
$ cd /opt/app/
|
||||||
|
|
||||||
|
### generate app
|
||||||
|
|
||||||
|
$ mojo generate app MojoApp
|
||||||
|
|
||||||
|
### start app
|
||||||
|
|
||||||
|
$ cd mojo_app/
|
||||||
|
$ morbo ./scripts/mojo_app prefork
|
||||||
|
|
||||||
|
### view page
|
||||||
|
|
||||||
|
Visit localhost:3000 in browser
|
||||||
20
lib/MojoApp.pm
Normal file
20
lib/MojoApp.pm
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package MojoApp;
|
||||||
|
use Mojo::Base 'Mojolicious', -signatures;
|
||||||
|
|
||||||
|
# This method will run once at server start
|
||||||
|
sub startup ($self) {
|
||||||
|
|
||||||
|
# Load configuration from config file
|
||||||
|
my $config = $self->plugin('NotYAMLConfig');
|
||||||
|
|
||||||
|
# Configure the application
|
||||||
|
$self->secrets($config->{secrets});
|
||||||
|
|
||||||
|
# Router
|
||||||
|
my $r = $self->routes;
|
||||||
|
|
||||||
|
# Normal route to controller
|
||||||
|
$r->get('/')->to('Example#welcome');
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
11
lib/MojoApp/Controller/Example.pm
Normal file
11
lib/MojoApp/Controller/Example.pm
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package MojoApp::Controller::Example;
|
||||||
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
|
|
||||||
|
# This action will render a template
|
||||||
|
sub welcome ($self) {
|
||||||
|
|
||||||
|
# Render template "example/welcome.html.ep" with message
|
||||||
|
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
3
mojo_app.yml
Normal file
3
mojo_app.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
secrets:
|
||||||
|
- usoPUHyzOvwMXLY3Gz-7NiLrqJ8uiyl-uBtIAlMaFc4UcIF7yzgf8y_mB6PXsPte69mO93R9n757Mt84MC3zhQL2AvQS71BPobLQ1FeGS_L8IBOCJ5aatrCInibVvrSAydRTEZzLSEYTFJUv87limhyfEY8OMDcnBRPb4C0Hb2A
|
||||||
11
public/index.html
Normal file
11
public/index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Welcome to the Mojolicious real-time web framework!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Welcome to the Mojolicious real-time web framework!</h2>
|
||||||
|
This is the static document "public/index.html",
|
||||||
|
<a href="/">click here</a> to get back to the start.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
11
script/mojo_app
Executable file
11
script/mojo_app
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Mojo::File qw(curfile);
|
||||||
|
use lib curfile->dirname->sibling('lib')->to_string;
|
||||||
|
use Mojolicious::Commands;
|
||||||
|
|
||||||
|
# Start command line interface for application
|
||||||
|
Mojolicious::Commands->start_app('MojoApp');
|
||||||
9
t/basic.t
Normal file
9
t/basic.t
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
use Mojo::Base -strict;
|
||||||
|
|
||||||
|
use Test::More;
|
||||||
|
use Test::Mojo;
|
||||||
|
|
||||||
|
my $t = Test::Mojo->new('MojoApp');
|
||||||
|
$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
|
||||||
|
|
||||||
|
done_testing();
|
||||||
9
templates/example/welcome.html.ep
Normal file
9
templates/example/welcome.html.ep
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
% layout 'default';
|
||||||
|
% title 'Welcome';
|
||||||
|
<h2><%= $msg %></h2>
|
||||||
|
<p>
|
||||||
|
This page was generated from the template "templates/example/welcome.html.ep"
|
||||||
|
and the layout "templates/layouts/default.html.ep",
|
||||||
|
<%= link_to 'click here' => url_for %> to reload the page or
|
||||||
|
<%= link_to 'here' => '/index.html' %> to move forward to a static page.
|
||||||
|
</p>
|
||||||
5
templates/layouts/default.html.ep
Normal file
5
templates/layouts/default.html.ep
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head><title><%= title %></title></head>
|
||||||
|
<body><%= content %></body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user