Laravel FrozenNode Administrator run in maintenance mode

a 夏天 提交于 2020-01-17 08:29:30

问题


My question is: How can I leave the Frozennode administrator runs normaly on Laravel Maintenance Mode?

This is what I got in global.php

App::down(function()
{
    return Response::view('maintenance', array(), 503);
});

Thanks!


回答1:


There is actually another way, more straightforward. As you can read in Laravel documentation, returning NULL from closure will make Laravel ignore particular request:

If the Closure passed to the down method returns NULL, maintenance mode will be ignored for that request.

So for routes beginning with admin, you can do something like this:

App::down(function()
{
  // requests beginning with 'admin' will bypass 'down' mode
  if(Request::is('admin*')) {
    return null;
  }

  // all other routes: default 'down' response
  return Response::view('maintenance', array(), 503);
});



回答2:


I've dug in the core, there's no way you can do it. Laravel checks for a file named down in app/storage/meta folder, if it's there, Laravel won't even call the routes, it'll just show the error page.

This is isDownForMaintenance function from laravel:

public function isDownForMaintenance()
{
    return file_exists($this['path.storage'].'/meta/down');
}

There's no configuration possible.

An alternative way to the laravelish "maintenance mode" is to set a new value in config/app.php, add:

'maintenance' => true,

Then add this to your before filter:

App::before(function($request)
{
    if(
        Config::get('app.maintenance') &&
        Request::segment(1) != 'admin' // This will work for all admin routes
        // Other exception URLs
    )
    return Response::make(View::make('hello'), 503);
});

And then just set :

'maintenance' => true,

To go back to normal mode



来源:https://stackoverflow.com/questions/17756785/laravel-frozennode-administrator-run-in-maintenance-mode

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