我正在使用Laravel 7.0。 我是否正在寻找一种仅在调试环境中显示调试页面的好方法? 如何在生产环境中隐藏?
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.mail.dsl.Mail;
import org.springframework.integration.mail.support.DefaultMailHeaderMapper;
import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.scheduling.support.PeriodicTrigger;
import javax.mail.internet.MimeMessage;
@Configuration
public class MailConfiguration {
@Bean
public IntegrationFlow imapMailFlow() {
return IntegrationFlows
.from(Mail.imapInboundAdapter("imaps://username:pass123@imap.gmail.com:" + 993 + "/INBOX")
.javaMailProperties(p -> p.put("mail.debug", "true"))
.headerMapper(mailHeaderMapper()),
e -> e.autoStartup(true).poller(p -> p.fixedDelay(5000)))
.handle(new MailHandler())
.get();
}
@Bean
public HeaderMapper<MimeMessage> mailHeaderMapper() {
return new DefaultMailHeaderMapper();
}
@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setTrigger(new PeriodicTrigger(1000));
return pollerMetadata;
}
}
答案 0 :(得分:0)
如果您有多个控制器/资源要应用此检查,则可以创建middleware并将其应用到路由中。
类似这样的东西:
Route::resource('/debug', 'DebugController')->middleware(['auth', 'debug');
如果仅需要在此控制器中进行此检查,则可以在构造函数中进行简单的中间件关闭。
类似这样的东西:
use Illuminate\Http\Response;
class DebugController extends Controller
{
public function __construct()
{
$this->middleware(function ($request, $next) {
if (app()->environment() === 'production') {
abort(Response::HTTP_FORBIDDEN);
}
return $next($request);
});
}
}
如果环境为production
,这将返回403响应,但是它将使请求在development
,local
,testing
等中通过。