我正在尝试用mojolicious制作我的第一个应用程序,我有一些路由问题。我有一个角度的应用程序,我只是想实现它,并使它在我的网站上工作。所以我有一个"app/index.html“文件,但是当我在地址"/appAngular”上时,我不知道如何让我的when服务器指向它。
我没有找到任何关于它的东西,即使它看起来是基本的,所以如果你能帮助我,我将不胜感激。
发布于 2017-08-31 00:16:53
如果您使用默认设置正确启动了web服务器,则您的浏览器将使用web服务器的ip指向x.x:3000。Mojolicious有一个登录页面,你可以在公共目录下添加.html文件,也会提供服务。因此,如果您的angular应用程序已经构建好了,那么整个结构将需要在public下,并且您将需要删除在新的mojolicious应用程序下提供的默认模板,应该如下所示:
get '/' => sub {
my $c = shift;
$c->render(template => 'index');
};重新开始的命令:
mojo generate lite_app myapp
mkdir public
<copy your angular app into new directory public>
<delete default route>
morbo myapp发布于 2018-11-27 15:37:50
您必须将您的index.html页面指定为Mojolicious中的静态页面。例如,在完整的应用中:
应用中的:
package MojoNg4;
use Mojo::Base 'Mojolicious';
use Mojo::SQLite;
# This method will run once at server start
sub startup {
my $self = shift;
# Load configuration from hash returned by "my_app.conf"
my $config = $self->plugin('Config');
$self->plugin('PODRenderer') if $config->{perldoc};
if (my $secrets = $self->config->{secrets}) {
$self->secrets($secrets);
}
$self->hook(
before_dispatch => sub {
my $c = shift;
$c->res->headers->header('Access-Control-Allow-Origin' => '*');
}
);
$self->helper( dbh => sub {state $dbh = Mojo::SQLite->new('sqlite:db/mojo-ng.db') });
$self->plugin(Minion => {SQLite => $self->dbh});
$self->plugin('Minion::Admin');
push @{$self->static->paths} => '/Users/Sachin/workspace/project/mojo_ng4/public/Demo';
# Router
my $r = $self->routes;
$r->get('/Demo/hello')->to('Demo#hello');
# Normal route to controller
#$r->get('/Demo/index.html')->to('Demo#index');
#$r->get('/Demo')->to('Demo#index');
}
1;上面的魔术线条是:
push @{$self->static->paths} => '/Users/Sachin/workspace/project/mojo_ng4/public/Demo';控制器中的:
package MojoNg4::Controller::Demo;
use Mojo::Base 'Mojolicious::Controller';
# This action will render a template
sub index {
my $self = shift;
# render demo app index page. rest of the routes will be taken care by
# angular4
$self->reply->static('Demo/index.html');
}
1;神奇的一句话是:
$self->reply->static('Demo/index.html');我有一个git repo,演示了如何使用Mojolicious为angular项目提供服务。请看一下:https://github.com/tryorfry/mojolicious-ng4
https://stackoverflow.com/questions/45964185
复制相似问题