Open leyume opened 3 years ago
I encountered this behavior while following the official documentation.
I added a second emit to verify it.
The first visit returns the route properly, at the second attempt it bypasses all other Routes and triggers the first Swoole\emit it encounters so in my case it returns 'Hello World' rather than 'Not Found'.
index.php:
<?php declare(strict_types=1);
require_once 'vendor/autoload.php';
use Siler\Swoole;
use Siler\Route;
use Siler\Twig;
Twig\init('pages');
$handler = function ($req) {
Route\get('/', 'pages/home.php');
Route\get('/todos', 'api/todos.php');
Swoole\emit('Hello World');
Swoole\emit('Not found', 404);
};
Swoole\http($handler)->start();
pages/home.php
<?php declare(strict_types=1);
use Siler\Swoole;
use Siler\Twig;
return fn() => Swoole\emit(Twig\render('home.twig'));
api/todos.php
<?php declare(strict_types=1);
use Siler\Swoole;
return function () {
Swoole\cors();
Swoole\json([
['id' => 1, 'text' => 'foo'],
['id' => 2, 'text' => 'bar'],
['id' => 3, 'text' => 'baz'],
]);
};
Exactly same behavior for me. Using fresh installed swoole with pecl and php 7.4, siler from composer.
Hello @leocavalcante Thank you for Siler.
There's this strange issue with v1.7.9 API returns 'Not Found' after first request with Siler Swoole
This worked fine up to version 1.7.8
Simple code to recreate
index.php
Then, api/get.php
Request API more than once. You would see the "Not Found"