Silex “->after” middleware usage

拈花ヽ惹草 提交于 2019-12-11 04:43:07

问题


I am testing Silex "->after" middleware to set the response header to enable CORS access. Silex is running V2.0.4.

My index.php excerpt as below:

$app->get('/{entity}/{func}', function ($entity, $func) use ($app) {
    if (method_exists($namespace, $func))
    {
        $result = call_user_func_array([$namespace, $func], [$app]);
        $status = 200;
    }
    $out = ['status' => $status, 'out' => $result];
    return json_encode($out);
})->after(function (Request $request, Response $response) {
        $response->headers->set('Access-Control-Allow-Origin', '*');
        $response->headers->set('Access-Control-Allow-Headers', 'Authorization');
    });

But the api will not display anything. If taken out the ->after portion, it returns the correct JSON string retrieved by relevant methods.

Would appreciate any hints on this.

来源:https://stackoverflow.com/questions/42837703/silex-after-middleware-usage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!