Created
December 22, 2016 20:23
-
-
Save Crell/b675682ca2e3d8fd2c6f8db11f61a681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Aerys\Host; | |
use Aerys\Router; | |
use Kelunik\Demo\Chat; | |
use function Aerys\root; | |
use function Aerys\websocket; | |
// route /ws to the websocket endpoint | |
// you can add more routes to this router | |
$router = (new Router()) | |
->route("GET", "ws", websocket(new Chat)); | |
// add document root | |
$root = root(__DIR__ . "/public"); | |
// Get the port from the environment. | |
$port = getenv('PORT') ?: 8080; | |
// create virtual host localhost:1337 | |
// requests will first be routed, if no route matches, the server tries to find a file in the document root | |
// you can add more responders or even multiple document roots to a single host | |
(new Host) | |
// ->name("localhost") | |
->expose("0.0.0.0", $port) | |
->use($router) | |
->use($root); | |
// $logger is the default Aerys logger which we can just use here to print a note | |
$logger->info("Open your browser and point it to http://localhost:" . $port . "/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment