core icon indicating copy to clipboard operation
core copied to clipboard

Flight::json with Flight::after('start'...

Open threethousand opened this issue 3 years ago • 8 comments

I have a filter after start, that updates a session cookie.

I have a route that returns Flight:json() and if the filter is active, nothing is returned for this route. connection just dies according to firefox. If the filter is removed, the json response for said route works perfect. what is that? or rather, how do i fix it?

edit* echo json_encode(....) instead of Flight::json works fine as well with the filter running after start.

threethousand avatar Jul 29 '21 12:07 threethousand

Could you please share code related to this issue?

magikstm avatar Jul 29 '21 13:07 magikstm

Flight::after('start', function() { Flight::serviceSession()->reload(); }

Flight::route('POST /account', array('actionAccount','main'));

class actionAccount { public static function main() { Flight::json(array('id' => 123)); } }

serviceSession()->reload function reloads a cookie. but even if i clear the whole function, things still break.

threethousand avatar Jul 29 '21 13:07 threethousand

json_encode is used by the framework: https://github.com/mikecao/flight/blob/master/flight/Engine.php#L501

The method you are using is used to send a response: https://github.com/mikecao/flight#json

This can be used to retrieve it: https://github.com/mikecao/flight#json-input

What is the exact error in Firefox? Did you try Chrome?

I don't see an issue with code above at the moment.

magikstm avatar Jul 29 '21 14:07 magikstm

yes, i want to send a response, not retrieve. im gonna have to keep digging but its so weird.

firefox says: "Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc." and the response is none i guess, its totally empty.

thank you for taking time.

threethousand avatar Jul 29 '21 14:07 threethousand

its something to do with Flight::after('start', because if i move the "Flight::serviceSession()->reload();" call into the actionAccount','main') function, and the contents of said function only is: public static function main() { Flight::serviceSession()->reload(); Flight::json(array('id' => 123)); }

then it works.

threethousand avatar Jul 29 '21 14:07 threethousand

Did you try changing the line: Flight::after('start', function() {

To: Flight::after('start', function(&$params, &$output) {

magikstm avatar Jul 29 '21 15:07 magikstm

didnt help :(((

threethousand avatar Jul 29 '21 15:07 threethousand

wrapping the response in exit() makes it work. exit(Flight::json(array('id' => 123)));

any issue with doing that?

threethousand avatar Jul 29 '21 15:07 threethousand

Is this still actual?

krmu avatar Jan 12 '24 08:01 krmu

If you still have this issue, go ahead and reopen this, otherwise we'll close it for now.

n0nag0n avatar Jan 13 '24 18:01 n0nag0n