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

Commit

Permalink
Add Swoole static assets example
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Jul 13, 2020
1 parent 602ca58 commit 3c0b351
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/swoole/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '3'
services:
swoole:
container_name: siler_swoole
image: leocavalcante/dwoole:1.0-development
image: leocavalcante/dwoole:dev
ports:
- '9501:9501'
volumes:
- ../../:/app
environment:
ENTRY_POINT_FILE: /app/examples/swoole/index.php
ENTRY_POINT_FILE: /app/examples/swoole/index.php
16 changes: 10 additions & 6 deletions examples/swoole/index.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
<?php declare(strict_types=1);

use Siler\Route;
use Siler\Swoole;
use Siler\Twig;

require_once __DIR__ . '/../../vendor/autoload.php';

Twig\init(__DIR__ . '/pages');

$server = function () {
$handler = function () {
Route\get('/', __DIR__ . '/pages/home.php');
Route\get('/todos', __DIR__ . '/api/todos.php');

// None of the above short-circuited the response with Swoole\emit().
Swoole\emit('Not found', 404);
};

Swoole\http($server)->start();
$server = Swoole\http($handler);
$server->set([
'enable_static_handler' => true,
'document_root' => __DIR__ . '/public',
]);
$server->start();
14 changes: 8 additions & 6 deletions examples/swoole/pages/_layout.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!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>
<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 %}
{% block page %}{% endblock %}
</body>
</html>
</html>
1 change: 1 addition & 0 deletions examples/swoole/public/assets/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Siler ❤️ Swoole')
3 changes: 3 additions & 0 deletions examples/swoole/public/assets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
color: pink;
}

0 comments on commit 3c0b351

Please sign in to comment.