I am not new to Spring MVC, but always wonder how can I use correct URLs (context name aware) inside JavaScript. Something like c:url or spring:url, but for JS:
E.g. if I have a webapp that is deployed as context in Tomcat. It has a page: http://localhost:8080/context/some/directory/search and API at http://localhost:8080/context/api. If page calls API, I face problems:
// This works wrong:
$http.get('/api/users', function(data){}) // will call http://localhost:8080/api/users - the context is lost!
$http.get('api/users', function(data){}) // will call http://localhost:8080/context/some/directory/api/users - wrong URL!
I wish some way of filtering exists:
$http.get('${url:api/users}', function(data){}) // will call http://localhost:8080/context/api/users
I saw something similar in C# and Ruby, and Python. Is there any ready-to-use solution for Java / Spring?
<script>in the html file where the javascript is loaded. Then you could form the URLs with this context. Btw, how did you do this in C#/Ruby/Python?@urlor:urlin Ruby. I understand that the problem is default servlet which does not filter JS, and in Ruby JS is served dynamically, but I hope some beauty way exists.