Developer-Dashboard
view release on metacpan or search on metacpan
lib/Developer/Dashboard/Web/App.pm view on Meta::CPAN
if ( $type eq 'js' ) {
return 'application/javascript; charset=utf-8';
}
elsif ( $type eq 'css' ) {
return 'text/css; charset=utf-8';
}
elsif ( $filename =~ /\.json$/i ) {
return 'application/json; charset=utf-8';
}
elsif ( $filename =~ /\.xml$/i ) {
return 'application/xml; charset=utf-8';
}
elsif ( $filename =~ /\.txt$/i ) {
return 'text/plain; charset=utf-8';
}
elsif ( $filename =~ /\.html?$/i ) {
return 'text/html; charset=utf-8';
}
elsif ( $filename =~ /\.svg$/i ) {
return 'image/svg+xml';
}
elsif ( $filename =~ /\.png$/i ) {
return 'image/png';
}
elsif ( $filename =~ /\.jpe?g$/i ) {
return 'image/jpeg';
}
elsif ( $filename =~ /\.gif$/i ) {
return 'image/gif';
}
elsif ( $filename =~ /\.webp$/i ) {
return 'image/webp';
}
elsif ( $filename =~ /\.ico$/i ) {
return 'image/x-icon';
}
else {
return 'application/octet-stream';
}
}
1;
__END__
=head1 NAME
Developer::Dashboard::Web::App - local web application for Developer Dashboard
=head1 SYNOPSIS
my $app = Developer::Dashboard::Web::App->new(
auth => $auth,
pages => $pages,
sessions => $sessions,
);
=head1 DESCRIPTION
This module handles the browser-facing dashboard routes, helper login flow,
page rendering modes, and page/action execution endpoints. It also provides
static file serving for JavaScript, CSS, and other assets from the public
directory structure (~/.developer-dashboard/dashboard/public/{js,css,others}).
=head1 METHODS
=head2 new, handle
Construct and dispatch the local web application.
=head2 _serve_static_file($type, $filename)
Serves static files from the public directory.
Input: $type (js, css, or others subdirectory), $filename (requested filename).
Output: array reference of [status_code, content_type, body].
Security: Prevents directory traversal attacks and verifies files are within
the public directory before serving.
=head2 _get_content_type($type, $filename)
Determines the MIME type for a file based on its type and extension.
Input: $type (js, css, or others), $filename (requested filename).
Output: MIME type string suitable for Content-Type header.
Supports: JS, CSS, JSON, XML, HTML, SVG, PNG, JPEG, GIF, WebP, ICO, and others.
=for comment FULL-POD-DOC START
=head1 PURPOSE
This module is the main route backend for the browser application. It handles login and logout, saved and transient page render/source/edit routes, status endpoints, saved Ajax endpoints, and the auth checks that decide whether a request is local adm...
=head1 WHY IT EXISTS
It exists because the dashboard browser surface is large and security-sensitive. Centralizing route behavior, auth gating, saved-page handling, Ajax endpoints, layered C<config/api.json> machine auth, and response shaping keeps the product behavior c...
=head1 WHEN TO USE
Use this file when changing browser routes, helper login behavior, page render/source/edit flows, saved Ajax endpoints, or the runtime JSON and HTML responses for dashboard workspaces.
=head1 HOW TO USE
Construct it with the action runner, auth service, config service, page store, prompt, page resolver, page runtime, and session store, then hand it to the Dancer adapter or PSGI bootstrap. Route-specific behavior belongs here rather than in the trans...
=head1 WHAT USES IT
It is used by C<Developer::Dashboard::Web::DancerApp>, by C<app.psgi>, by the CLI web server wrapper, and by the broad web/browser regression suite that covers routes, auth, Ajax, and workspace behavior.
=head1 EXAMPLES
Example 1:
perl -Ilib -MDeveloper::Dashboard::Web::App -e 1
Do a direct compile-and-load check against the module from a source checkout.
Example 2:
prove -lv t/03-web-app.t t/08-web-update-coverage.t t/web_app_static_files.t
Run the focused regression tests that most directly exercise this module's behavior.
Example 3:
HARNESS_PERL_SWITCHES=-MDevel::Cover prove -lr t
Recheck the module under the repository coverage gate rather than relying on a load-only probe.
Example 4:
prove -lr t
Put any module-level change back through the entire repository suite before release.
=for comment FULL-POD-DOC END
=cut
( run in 1.173 second using v1.01-cache-2.11-cpan-524268b4103 )