Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

baseUrl is not absolute #1

Closed
ismell opened this issue Jan 24, 2012 · 5 comments
Closed

baseUrl is not absolute #1

ismell opened this issue Jan 24, 2012 · 5 comments

Comments

@ismell
Copy link

ismell commented Jan 24, 2012

My template has the following

{% block javascripts %}
    {{ parent() }}
    <script type='text/javascript'>require(['wedcore/edit'], function() {})</script>
{% endblock %}

My Config looks like so


hearsay_require_js:
    base_directory: %kernel.root_dir%/scripts
    paths: 
        jquery:
            location: //ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min
            external: true
        wedcore: '@WedCoreBundle/Resources/scripts'
    optimizer:
        path: /path/to/r.js
        excludes: [ excluded/module ] # Modules to exclude from the build (optional)
        options: { skipModuleInsertion: true } # Additional options to pass to the optimizer (optional)

When I hit the following url: http://rangelwed/app_dev.php/reception/edit

My require block generates the following

<script type='text/javascript'>var require={"baseUrl":"js","locale":null,"paths":{"jquery":"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.1\/jquery.min"}}</script><script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/require.js/1.0.1/require.min.js'></script>

<script type='text/javascript'>require(['wedcore/edit'], function() {})</script>

if you notice the baseUrl it's relative. This causes the request to wedcore/edit to go to http://rangelwed/app_dev.php/reception/js/wedcore/edit.js. This is incorrect and instead should go to http://rangelwed/app_dev.php/js/wedcore/edit.js.

So the base URL should be rendered as /app_dev.php/js/.

Thanks,
Raul

@bigethan
Copy link

in your config.yml you can specify

hearsay_require_js:
    ...
    base_url: /js 

in your main config, and then in your config_dev.yml do:

hearsay_require_js:
    base_url: /app_dev.php/js

and that should get you want you want.

@kmontag kmontag closed this as completed in 15d65bd Mar 5, 2012
@kmontag
Copy link
Member

kmontag commented Mar 5, 2012

Fixed; note that @bigethan 's workaround breaks as a result, though. The base_url specified in the config will now be automatically appended to the request root, regardless of whether it contains a leading slash.

@ismell
Copy link
Author

ismell commented Mar 5, 2012

Awesome thanks!

@AsaAyers
Copy link

AsaAyers commented Mar 5, 2012

Your commit works as long as your .htaccess is working to hide the /app.php part of the URL. Maybe it should check if kernel.debug is set? Or maybe see how assetic figures out the URL for production?

@kmontag kmontag reopened this Mar 12, 2012
@kmontag
Copy link
Member

kmontag commented Mar 12, 2012

Base URL is now chosen based on the value of %assetic.use_controller%. If a controller is being used for assets, the root path (e.g. app.php or app_dev.php) will be included in the base URL (unless it's being hidden by .htaccess). Otherwise, the base URL is just the one specified in your config.

This feels a bit tightly tied to the Assetic Bundle implementation; if anyone has thoughts on a better way to do it, suggestions or pull requests are appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants