Symfony 3/FOSJsRoutingBundle: not allowed to access router.js

919 views Asked by At

I'm trying to install a Symfony 3.1.4 project on a managed server. It works perfectly on my local machine, but not on the external.

For JS routing I use FOSJsRoutingBundle, version ^1.6.

Problem:

When I visit http://mydomain.tld, the browser tries to load http://mydomain.tld/bundles/fosjsrouting/js/router.js, but is not allowed to: 403 Forbidden.

For my understanding the file exists, but I'm not allowed to load it.

Solving approach:

  • php bin/console cache:clear --env=prod
  • php bin/console fos:js-routing:dump
  • php bin/console assets:install --symlink web
  • chmod for web/bundles/*: 755

Nothing worked.

Could it be related to the symlinks? I'm a bit lost and. Any ideas?

Thanks in advance!

Edit 1: security.yml

security:
    providers:
        in_memory:
            memory: ~
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            remember_me:
                secret:   '%secret%'
                lifetime: 604800 
                path:     /
            pattern: ^/
            form_login:
                provider: fos_userbundle                  
                login_path: fos_user_security_login
                check_path: fos_user_security_check
                csrf_token_generator: security.csrf.token_manager

            logout:
                path: fos_user_security_logout
                target: index
            anonymous: true
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN: ROLE_USER

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: /admin/, role: ROLE_ADMIN }
        - { path: /dashboard, role: ROLE_USER }
1

There are 1 answers

0
Tony On

I recently had this issue and this is what worked for me in Symfony 3.4:

In config.yml, you need to add a package to the assets config with the base_path set to /bundles. This makes the route public and should allow you to pull any asset file from any bundle installed. Of course, you can instead add a package per bundle if you wish to do so.

config.yml

framework:
    assets:
        packages:
            bundles:
                base_path: '/bundles'