在 perl dancer2 MVC 框架中将 html 文件作为路由传递

Pass html file as a route in perl dancer2 MVC framework

我的机器上有一个文件 /abc/assets/file/

我想return这个文件作为路由。可以这样做吗?

您通常会在 PSGI 文件中的 Dancer 之外使用安装在同一 PSGI 文件中的不同 Plack 应用程序执行此操作。查看整个目录的 Plack::App::File for an individual file, or Plack::App::Directory

您的 PSGI 文件将如下所示。

#!/usr/bin/env perl

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";

use MyApp; # this is Dancer2-based
use Plack::Builder;
use Plack::App::File;
use Plack::App::Directory;

builder {
    mount '/' => MyApp->to_app;
    mount '/abc-file' => Plack::App::File->new(
        file => '/abc/assets/file')->to_app;
    mount '/foo' => Plack::App::Directory->new({ 
        root => "/xyz/foo" })->to_app;
};