2017 © Pedro Peláez
 

library http-server-static-content

Static content responder for Amp's HTTP server.

image

amphp/http-server-static-content

Static content responder for Amp's HTTP server.

  • Wednesday, June 20, 2018
  • by kelunik
  • Repository
  • 4 Watchers
  • 7 Stars
  • 613 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

http-server-static-content

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. This package provides an HTTP server plugin to serve static files like HTML, CSS, JavaScript, and images effortlessly., (*1)

Installation

This package can be installed as a Composer dependency., (*2)

composer require amphp/http-server-static-content

Usage

This package provides two RequestHandler implementations: - DocumentRoot: Serves all files within a directory. - StaticResource: Serves a single specific file., (*3)

The example below combines static file serving and request routing to demonstrate how they work well together:, (*4)

<?php

use Amp\Http\Server\DefaultErrorHandler;
use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
use Amp\Http\Server\Response;
use Amp\Http\Server\SocketHttpServer;
use Amp\Http\Server\StaticContent\DocumentRoot;
use Amp\Http\Status;

$router = new Amp\Http\Server\Router;
// $server is an instance of HttpServer and $errorHandler an instance of ErrorHandler
$router->setFallback(new DocumentRoot($server, $errorHandler, __DIR__ . '/public'));
$router->addRoute('GET', '/', new ClosureRequestHandler(function () {
    return new Response(Status::OK, ['content-type' => 'text/plain'], 'Hello, world!');
}));


$server->start($router, new DefaultErrorHandler());

A full example is found in examples/server.php., (*5)

Contributing

Please read our rules for details on our code of conduct, and the process for submitting pull requests to us., (*6)

Security

If you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker., (*7)

License

The MIT License (MIT). Please see LICENSE for more information., (*8)

The Versions

20/06 2018