I have the following:
#App.module "LocationGridApp", (LocationGridApp, App, Backbone, Marionette, $, _) ->
API =
showLocationGrid: ()->
LocationGridApp.Show.Controller.showLocationGrid(2)
class LocationGridApp.Router extends Marionette.AppRouter
appRoutes:
"" : "showLocationGrid"
controller: API
App.on 'before:start', ->
new LocationGridApp.Router
When I access <url> I get the showLocationGrid to fire off as expected. When I visit <url>/companies, showLocationGrid is still firing. I was expecting <url>/companies to be handled by my server. Is the empty route doing something I'm not expecting?
main_app.js.coffee
#App = do(Backbone, Marionette) ->
Arc = new Marionette.Application
Arc.addRegions
container: "#container"
Arc.on "start", ->
if Backbone.history
Backbone.history.start(pushState: false)
Arc
It's up to your server to serve different files depending on the route: if you get the same result for <url> and <url>/companies, it is that your server answered with the same static files. Nothing in your client-side code can take over your server-side routing. You should probably inspect your server routing settings.
Related
I am trying to implement signalR in angularJS,
I want to pass relative url to hub connection, but it's making current url (on which my angular application is hosted)
My API base url : http://localhost:81/NrsService/api/TestSignal
My angular application running at
http://localhost:81
Here is my signalR setup :
$.connection.hub.url = "/NrsService/api/TestSignal";
//Getting the connection object
connection = $.hubConnection();
Like it is sending request at http://localhost:81/signalr/negotiate? but I want it to be http://localhost:81/NrsService/api/TestSignal/negotiate?
You have to edit the generated JavaScript code where the client proxy is defined. As of SignalR 2.4.0 there is a createHubProxies function defined where you should find this line of code:
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
Change it to the following to prevent the "/signalr" ending in your requests:
signalR.hub = $.hubConnection("", { useDefaultPath: false });
After that, you can simply change the url which should be called the way you provided in your question, e.g.:
$.connection.hub.url = "/NrsService/api/TestSignal";
If you also want to change this Url dynamically, you can use the document.location properties. In my case, I did something like this:
var subPath = document.location.pathname.substr(0, document.location.pathname.lastIndexOf("/"));
$.connection.hub.url = subPath; // subpath equals to "/NrsService/api"
Hope this helps.
I was following the backbonerails.com screencast episode 6. But I can't get the routing to work as it was explained.
Here is my code that is similar to what the screencast suggest:
#Report.module "UsersApp", (UsersApp, App, Backbone, Marionette, $, _) ->
class UsersApp.Router extends Marionette.AppRouter
initialize: ->
console.log "Happy days"
appRoutes:
"users" : "listUsers"
API =
listUsers: ->
console.log "hallo"
App.addInitializer ->
console.log "cheers"
new UsersApp.Router
controller: API
As you can see I have tried to add console.log in a few places to make sure the addInitializer is working and that the Router is started... but still the routing to #users does not do the corresponding console.log
I have this where I define the app:
App.on "initialize:after", ->
if Backbone.history
Backbone.history.start()
So that should run after router has started, if I understand it all.
Turns out that it was the Backbone history was not running. I found that out by running:
Backbone.History.started
in my console. For some reason
App.on "initialize:after", ->
if Backbone.history
Backbone.history.start()
did not start the history.
EDIT: turns about in v2 and above of Marionette you should use:
App.on "start", ->
I try to study and use Backbone/Marionette in my project. Now I stuck with Router navigation which work not as I though it should.
class MyApp.Router extends Marionette.AppRouter
appRoutes :
'info/:place/(:what)' : 'places_page'
MyApp.Controller = ->
places_page: (place,what)->
console.log 'Triggered places_page'
MyApp.addInitializer( ->
controller = new MyApp.Controller()
new MyApp.Router
controller: controller
Backbone.history.start( pushState: false )
)
MyApp.vent.on('do:search', ->
console.log 'triggered do:search'
place = 'Moscow'
what = 'Пицца'
info_model.set place: place, item:what
new_url = 'info/'+where+'/'+what
if new_url != decodeURIComponent(Backbone.history.fragment)
Backbone.history.navigate(new_url, {trigger: false})
On initial load of site.com/#info/Budapest/Vine page or reload it, I get Triggered places_page message as I expect.
But when I fire do:search event which update url to site.com/#info/Moscow/Пицца, I get Triggered places_page again! So it reload all my views from scratch instead of just change url and re-render one model.
What I can do wrong here?
Update 2:
Found strange thing. If I use latin letters in new url, everything work like it should.
But if I use cyrillic in new url path, it will trigger route function.
Backbone: 1.0, Marionette:v1.0.3, jquery: 1.9.1
Mystery solved!
That happens because of non-latin symbols in url.
Correct code:
new_url = 'info/'+encodeURIComponent(where)+'/'+encodeURIComponent(what)
if new_url != Backbone.history.fragment
Backbone.history.navigate(new_url, {trigger: false})
Because Backboune.navigate don't execute navigate if url didn't change and trigger is false by default, I can write it simple like that:
new_url = 'info/'+encodeURIComponent(where)+'/'+encodeURIComponent(what)
Backbone.history.navigate(new_url)
Backbone.history takes an object when starting. Try this syntax in CoffeeScript:
Backbone.history.start
pushState: false
In addition, pushState is false by default, so you can just have Backbone.history.start()
Does this solve your issue?
Proper URL encoding is required. I couldn't find this in the docs of Backbone related to the router functionality.
I had the same issue, alas with spaces in the query part, i.e.:
#app/terms?filter=java ee
Together with the encodeURIComponent solution as described in your answer, I also found the following lines of comments in backbone.js (1.0.0), pertaining to the navigate function:
// Save a fragment into the hash history, or replace the URL state if the
// 'replace' option is passed. You are responsible for properly URL-encoding
// the fragment in advance.
I'm fetching data using backbone.js with the following code. The .get and .set commands work fine, but if I set JSON data, then use .save(), I get a 404 (Not Found) error.
var ExampleModel = Backbone.Model.extend({});
var example = new ExampleModel({});
example.url = "data/example.json";
example.fetch();
I'm using a basic server with the connect.js module:
var util = require('util'),
connect = require('connect'),
port = 8080;
connect.createServer(connect.static(__dirname)).listen(port);
util.puts('Listening on ' + port + '...');
and example.json looks like so:
{
"home": "new york",
"status": "married",
"kids": "one"
}
Is the problem with my server? Any help will be greatly appreciated.Thanks!
This might sound dumb but it is similar to a problem I had a few months ago with one of my backbone applications running with rails as a web server. Try defining the model 'url' adding a backlash at the beggining like this:
var ExampleModel = Backbone.Model.extend({
url: '/data/example.json'
});
In my example I define the url attribute inside the model because I think it's cleaner but you can do differently if you like.
I am having problems getting the logout link work in GAE (Python).
This is the page I am looking at.
In my template, I create a link
<p>Logout</p>
But when I click on it I get "broken link" message from Chrome. The url for the link looks like this:
http://localhost:8085/users.create_logout_url(
My questions:
Can anybody explain how this works in general?
What is the correct url for the dev server?
What is the correct url for the app server?
What is the ("/") in the logout url?
Thanks.
EDIT
This link works; but I don't know why:
<p>Logout</p>
What sort of templates are you using? It's clear from the output that you're not escaping your code correctly.
Seems to me that you want to do this instead:
self.response.out.write("This is the url: %s", users.create_logout_url("/"))
You could also pass it to your template, using GAEs implemented django templates.
from google.appengine.ext.webapp import template
...
...
(inside your request handler)
class Empty: pass
data = Empty()
data.logout = users.create_logout_url("/")
self.response.out.write(template.render(my_tmpl, {'data': data})
A useful approach is to add all sorts of info to a BaseRequestHandler and then use this as base class for all of your other request handler classes.
from google.appengine.ext import webapp
...
class BaseRequestHandler(webapp.RequestHandler):
def __init__(self):
webapp.RequestHandler.__init__(self) # extend the base class
class Empty: pass
data = Empty()
data.foo = "bar"
Then your new classes will have access to all the data you provided in the base class.
class OtherHandler(BaseRequestHandler):
def get(self):
self.response.out.write("This is foo: %s" % self.data.foo) # passes str "bar"
Hope it helps.
A.
Hi following more or less what this article is showing for the user account stuff. In gwt I store server side the logout/login url and I pass them to the client
http://www.dev-articles.com/article/App-Engine-User-Services-in-JSP-3002