header([ 'Content-Type' => 'text/event-stream', 'Cache-Control' => 'no-cache, must-revalidate', ]); }); Route::get('/websocket', function () { return (new \think\worker\response\Websocket()) ->onOpen(function (\think\worker\Websocket $websocket) { $websocket->join('foo'); }) ->onMessage(function (\think\worker\Websocket $websocket, \think\worker\websocket\Frame $frame) { $websocket->to('foo')->push($frame->data); }); }); Route::get('test', 'index/test'); Route::post('json', 'index/json'); Route::get('static/:path', function (string $path) { $filename = public_path() . $path; return new \think\worker\response\File($filename); })->pattern(['path' => '.*\.\w+$']);