Environment Middleware

This class is included with the starter site and provides a template with common options for environment middleware. Modify this class as needed for your site.

Example usage that only allows a route if the user is on a local network and then loads a [.env] file prior to the route running:

    $app->get('/url', 'Controller')

Source Code


Example Code

Starter Site Middleware

// The FastSitePHP Starter Site includes several examples pages and provides
// a basic directory/file structure. The site is designed to provide structure
// for basic content (JavaScript, CSS, etc) while remaining small in size so
// that it is easy to remove files you don’t need and customize it for your site.
// Core Middleware classes are provided and can be modified for your site.
// To use them specify the 'Class.method' on route filter functions or
// when mounting additional files.

// Require a user to be logged in in order to use a page
$app->get('/secure-page', 'SecureController')->filter('Auth.hasAccess');

// Require an authenticated user and use CORS
    ->get('/api/:record_type', 'ApiController.getData')

// Only run a route from localhost
$app->get('/server-info', function() {

// Only load a file if running from localhost
$app->mount('/sysinfo/', 'routes-sysinfo.php', 'Env.isLocalhost');



Return true if the request is running from localhost '' (IPv4) or '::1' (IPv6) and if the web server is also running on localhost.

Returns: bool


Return true if the web request is coming a local network. (for example or

Returns: bool


Return true if the web request is coming a local network and and a Proxy Server such as a Load Balancer is being used.

Returns: bool

loadDotEnv(Application $app)

Loads environment variables from a [.env] file into [getenv()] and [$_ENV].