|
...
|
...
|
@@ -13,13 +13,23 @@ class SimpleServerCoroutine |
|
|
|
{
|
|
|
|
$this->httpServer = new Server($host, $port, $ssl);
|
|
|
|
}
|
|
|
|
public function router($method, $path, $callback)
|
|
|
|
public function router(array $method, $path, $callback)
|
|
|
|
{
|
|
|
|
$this->httpServer->handle($path, function (Request $request, Response $response) use ($method, $callback) {
|
|
|
|
$m = $request->getMethod();
|
|
|
|
foreach ($method as $k => $v) {
|
|
|
|
$method[$k] = strtolower($v);
|
|
|
|
}
|
|
|
|
$m = strtolower($m);
|
|
|
|
if (!in_array($m, $method)) {
|
|
|
|
$response->status(405);
|
|
|
|
$response->end();
|
|
|
|
$data = [
|
|
|
|
'code' => 405,
|
|
|
|
'msg' => 'Method Not Allowed',
|
|
|
|
'currentMethod' => $m,
|
|
|
|
'allowMethod' => $method,
|
|
|
|
];
|
|
|
|
$response->end(json_encode($data));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$requestInfo = [
|
...
|
...
|
|