Skip to content

Instantly share code, notes, and snippets.

@robinvdvleuten
Created April 11, 2016 11:19
Show Gist options
  • Save robinvdvleuten/1d74aa8a7155bcbf580e6d8bd68c3a94 to your computer and use it in GitHub Desktop.
Save robinvdvleuten/1d74aa8a7155bcbf580e6d8bd68c3a94 to your computer and use it in GitHub Desktop.
<?php
$filename = __DIR__.'/../dist/'.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;
}
require_once __DIR__.'/../vendor/autoload.php';
use Aws\Lambda\LambdaClient;
use Silex\Application;
$app = new Application();
$app['debug'] = true;
$app->get('/', function () use ($app) {
$client = LambdaClient::factory([
'version' => 'latest',
'region' => 'eu-west-1',
]);
$payload = json_encode(['name' => 'Server']);
$result = $client->invoke([
'FunctionName' => 'php-react-lamda-example',
'Payload' => $payload,
]);
$markup = json_decode((string) $result->get('Payload'));
return <<<EOF
<html>
<head>
<meta charset="utf-8">
<title>php-react-lamda-example</title>
</head>
<body>
<div id="root">$markup</div>
<script>
window.__INITIAL_PAYLOAD__ = $payload;
</script>
<script src="/bundle.js"></script>
<body>
</html>
EOF;
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment