Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #352 from leocavalcante/master
Browse files Browse the repository at this point in the history
Add static assets section
  • Loading branch information
leocavalcante authored Jul 13, 2020
2 parents 0cc012a + 7b93283 commit 602ca58
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion docs/swoole.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,52 @@ return fn() => Swoole\emit($html);

This avoids the template to be re-rendered on each request unnecessarily.

### Serving static assets

The `Siler\Swoole\http` function returns a plain `Swoole\Http\Server` so you can give it to a variable and use regular methods from Swoole's documentation like `set`:

{% tabs %}
{% tab title="index.php" %}
```php
/*
├───api
├───pages
└───public
└───assets
*/
$server = Swoole\http($handler);
$server->set([
'enable_static_handler' => true,
'document_root' => __DIR__ . '/public',
]);
$server->start();
```
{% endtab %}

{% tab title="pages/\_layout.twig" %}
```markup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Siler + Swoole</title>
<link rel="stylesheet" href="/assets/styles.css">
<script defer src="/assets/scripts.js"></script>
</head>
<body>
{% block page %}{% endblock %}
</body>
</html>
```
{% endtab %}
{% endtabs %}

## Request's Query string, Body & Headers

Since there is no web server module or CGI layer, things like $\_GET won't work for query string parameters etc. **But fear nothing**, Siler provides getters for both Swoole's Request and Response objects: `Siler\Swoole\request()` and `Siler\Swoole\response()`.
Expand Down Expand Up @@ -300,7 +346,7 @@ $todos = [
['id' => 3, 'text' => 'baz'],
];
return function () use ($todos) {
return function () {
Swoole\cors();
Swoole\json($todos);
};
Expand Down

0 comments on commit 602ca58

Please sign in to comment.