2017 © Pedro Peláez
 

library react-http-static

A helper around react/http for creating static web servers

image

jalle19/react-http-static

A helper around react/http for creating static web servers

  • Friday, October 28, 2016
  • by Jalle19
  • Repository
  • 1 Watchers
  • 1 Stars
  • 92 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

react-http-static

Build Status Scrutinizer Code Quality Coverage Status, (*1)

This is a very basic helper for creating static web servers using react/http. It serves files from a specified directory and can optionally be configured to require authentication., (*2)

Requirements

  • PHP >= 5.6

Installation

composer require jalle19/react-http-static

Usage

This example will serve the directory /var/www on port 8080. Additionally it will require clients to authenticate using the username admin and the password admin., (*3)

<?php

require_once('vendor/autoload.php');

use Jalle19\ReactHttpStatic\Authentication\Handler\Basic as BasicAuthenticationHandler;
use React\Http\Server as HttpServer;
use React\Socket\Server as Socket;

// Create an event loop. You'll probably want to use your own application's loop instead of creating a new one.
$eventLoop = \React\EventLoop\Factory::create();

// Create the socket to use
$socket = new Socket($eventLoop);
$socket->listen(8080);

// Create the server itself
$httpServer      = new HttpServer($socket);
$staticWebServer = new Jalle19\ReactHttpStatic\StaticWebServer($httpServer, '/var/www');

// Apply our authentication handler
$handlerCallback = function ($username, $password) {
    return $username === 'admin' && $password === 'admin';
};

$staticWebServer->setAuthenticationHandler(new BasicAuthenticationHandler('our fancy realm', $handlerCallback));

// Start the loop
$eventLoop->run();

Index handling

Requests for the root path (/) are mapped to index.htm or index.html by default, whichever is found first. You can override this behavior like this:, (*4)

$staticWebserver->setIndexFiles([
    'foo.html',
    'bar.html',
]);

Authentication

You can write your own authentication handlers by implementing Jalle19\ReactHttpStatic\Authentication\Handler\HandlerInterface., (*5)

Logging requests

You can log requests by passing a PSR-3 compatible logger to the server's constructor or by calling setLogger()., (*6)

License

MIT, (*7)

The Versions

28/10 2016

dev-master

9999999-dev

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall

28/10 2016

0.1.4

0.1.4.0

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall

28/10 2016

0.1.3

0.1.3.0

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall

01/06 2016

0.1.2

0.1.2.0

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall

31/05 2016

0.1.1

0.1.1.0

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall

31/05 2016

0.1.0

0.1.0.0

A helper around react/http for creating static web servers

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sam Stenvall