Skip to content

Instantly share code, notes, and snippets.

@Crell
Created December 22, 2016 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crell/b675682ca2e3d8fd2c6f8db11f61a681 to your computer and use it in GitHub Desktop.
Save Crell/b675682ca2e3d8fd2c6f8db11f61a681 to your computer and use it in GitHub Desktop.
<?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