https://mysite.com/MySuperGreatDiscountCode will automatically apply the code to the user's cart. It is also used to allow admin users of the application to be able to create random pages in our headless CMS without having to specifically define routes to those pages. The way Folio seems to work is that it also defines a fallback route that kicks off its route resolution process. What I'm currently experiencing is that Folio's fallback route is never called, and my already existing one handles the requests. When I remove my existing fallback route, Folio starts working as expected, but, as you've guessed, I lose the ability to have requests that point to a code or a CMS page. In trying to get Folio to play nice with my application I've been looking at different ways for handling requests for discount codes or pages that only exist in the CMS. My first thought was to use a middleware that would look for a 404 status code on the response, and if one is found, it would execute the logic to see if the request was for a discount code or a CMS page and return the appropriate response. However I couldn't get this to work because it seems the Laravel Exception handler "short circuits" the middleware stack when an exception is thrown/rendered. My IsItA404Response middleware was never being called when a NotFoundHttpException was being thrown. This lead me to move the discount code/cms page resolution logic to the Exception Handler's render method. This is working, but it seems a bit "hacky" to me. I'm curious to know what everyone thinks of using the Exception Handler in this way or if you have a better idea of how to handle this. submitted by /u/adear11 [link] [comments]
Fallback route vs Exception handler for handling otherwise undefined routes/pages
I have an existing application that I'm looking to incorporate Laravel Folio into. I've come across something of a conflict between Folio and the existing routes in my application that has led me to consider what is the "best" way to handle requests for pages without a specific route definition.
My application already has a fallback route defined. In my application I use the fallback route to allow for links to promo/discount codes that are applied to purchases a user makes so that requests like
https://mysite.com/MySuperGreatDiscountCode will automatically apply the code to the user's cart. It is also used to allow admin users of the application to be able to create random pages in our headless CMS without having to specifically define routes to those pages. The way Folio seems to work is that it also defines a fallback route that kicks off its route resolution process. What I'm currently experiencing is that Folio's fallback route is never called, and my already existing one handles the requests. When I remove my existing fallback route, Folio starts working as expected, but, as you've guessed, I lose the ability to have requests that point to a code or a CMS page. In trying to get Folio to play nice with my application I've been looking at different ways for handling requests for discount codes or pages that only exist in the CMS. My first thought was to use a middleware that would look for a 404 status code on the response, and if one is found, it would execute the logic to see if the request was for a discount code or a CMS page and return the appropriate response. However I couldn't get this to work because it seems the Laravel Exception handler "short circuits" the middleware stack when an exception is thrown/rendered. My IsItA404Response middleware was never being called when a NotFoundHttpException was being thrown. This lead me to move the discount code/cms page resolution logic to the Exception Handler's render method. This is working, but it seems a bit "hacky" to me. I'm curious to know what everyone thinks of using the Exception Handler in this way or if you have a better idea of how to handle this. submitted by /u/adear11 [link] [comments]
https://mysite.com/MySuperGreatDiscountCode will automatically apply the code to the user's cart. It is also used to allow admin users of the application to be able to create random pages in our headless CMS without having to specifically define routes to those pages. The way Folio seems to work is that it also defines a fallback route that kicks off its route resolution process. What I'm currently experiencing is that Folio's fallback route is never called, and my already existing one handles the requests. When I remove my existing fallback route, Folio starts working as expected, but, as you've guessed, I lose the ability to have requests that point to a code or a CMS page. In trying to get Folio to play nice with my application I've been looking at different ways for handling requests for discount codes or pages that only exist in the CMS. My first thought was to use a middleware that would look for a 404 status code on the response, and if one is found, it would execute the logic to see if the request was for a discount code or a CMS page and return the appropriate response. However I couldn't get this to work because it seems the Laravel Exception handler "short circuits" the middleware stack when an exception is thrown/rendered. My IsItA404Response middleware was never being called when a NotFoundHttpException was being thrown. This lead me to move the discount code/cms page resolution logic to the Exception Handler's render method. This is working, but it seems a bit "hacky" to me. I'm curious to know what everyone thinks of using the Exception Handler in this way or if you have a better idea of how to handle this. submitted by /u/adear11 [link] [comments]
0 comments:
Post a Comment
Thanks