1

I am developing a page within Symfony 4 that requires the FOSJSrouting bundle. Within my DEV environment - using docker - I got it working fine using the steps below.

However, in my prod environment I keep getting the errors:

- http://url/js/routing?callback=fos.Router.setData 500 (Internal Server Error)
- router.min.js:1 Uncaught Error: The route "get_coinTicker_from_platform" does not exist.

My steps to get it working in DEV:

  • $ composer require friendsofsymfony/jsrouting-bundle
    
  • Adding the following to routes.yaml:

    fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
    
  • Adding the following to my base.html.twig

    <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
    <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
    

This was sufficient to get my exposed routes to work:

/**
 * @Route("/ticker/{coin}/{plat}", name="get_coinTicker_from_platform", options={"expose"=true})
 */

Then in my JavaScript I did:

$.ajax({
method: 'POST',
url: Routing.generate('get_coinTicker_from_platform', {coin: coin.val(), plat: exch.val()})
}).done(function(data) {
$('.loader').hide();
}
});

I installed the routing bundle using composer on my Linux server and even tried the steps included in the docs to publish assets as well as dump routes like so:

bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

I have checked the symfony and Apache logs. Nothing is hinting about this issue there. Everything else is running fine, just FOSrouting is causing trouble. Also, I tried:

npm install fos-routing --save

This actually temporarily solved the issue, but the next day, after I did another rsync from my local repository it was broken again.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Stormnorm
  • 171
  • 4
  • 11
  • You should check your symfony logs. – Iwan Wijaya Jun 11 '18 at 11:50
  • I have checked both apache logs as well as the log under var/log/prod.log. Prod.log doesn't list anything. Apache logs don't hint at anything related to this either... – Stormnorm Jun 11 '18 at 14:10
  • I think you have missed asset install, try asset install, then run fos:js-routing dump then include following in base html 'web/bundles/fosjsrouting/js/router.js' and 'web/js/fos_js_routes.js' – Samiul Amin Shanto Jun 14 '18 at 09:47

3 Answers3

3

I had the same problem and it has been solved by giving the right rwxrwxrwx on the folder var/cache/prod.

Matthew
  • 1,905
  • 3
  • 19
  • 26
Nelly34
  • 41
  • 2
1

I am a fair bit late to the party but anyway let's get into it.

I think your issue - as hinted by @Samiul Amin Shanto comes from cached content that is not wiped out before dumping the routes.

In prod environment, symfony caches the Router. So if you do not wipe the cache and update your code with new actions in your controller for example, they won't be available at all because the route is not referencing them yet.

Hopefully you somehow managed to find this out because at some point you did run cache:clear --env=prod So I'm just putting out this response here for any other internet user who might come across this question.

Take care.

Giorgiolino
  • 165
  • 10
0

Just in case someone has the same issue, I also spent about 2 hours on this, the actual issue is the right permission on the var folder inside your symfony project. Just refer to symfony official docs for giving the right permission here!

ahmadzai
  • 44
  • 5