Abbett.org

Getting "normal" URLs with Backbone, PushState, and Apache

While developing the UI for ACT.md, I've been using the hash-based URLs that work by default with the Backbone.js Router.

When it came time for automated browser testing with Selenium IDE, everything came to a halt. When Selenium opens a URL that's just a change of hash, it won't detect the (obviously visible) page change and the open command times out. (Unfortunately, my bug submission has yet to be addressed.)

So, I finally bit the bullet and set up my environment to support "normal" URLs. These were the basic steps (with links to the resources I consulted):

  1. Create/edit .htaccess file to rewrite URLs
  2. Add { pushState: true } option to Backbone.history.start()
  3. Edit all URLs in your code to remove the #/
  4. Add { trigger: true } option to all application.navigate() calls
  5. Hijack all internal link clicks and pass URLs to navigate() (thanks @tbranyen)
Comments [0]

Setting up mod_wsgi on WampServer

I'm using Windows 7 and Python 2.7. I'm running a Flask app as alias /api/

General Resources

Installing mod_wsgi

  1. Install Python
  2. Install a 32-bit version of WampServer
  3. Download mod_wsgi Windows binary and copy into WampServer's /bin/apache/apacheX.X.X/modules directory
  4. Edit WampServer's httpd.conf file to load the new module, around line 128, e.g.

    LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
    

Configuring a WSGIScriptAlias

  1. Create a WSGI file. Here's mine, stored with our application code, referencing our package act.rest.app:

    import sys
    sys.path.insert(0, 'c:/path/to/python/application/code')
    from act.rest.app import app as application
    
  2. Use the WampServer system tray interface to create a basic Apache alias Creating an alias in WampServer

  3. Use same interface to "Edit the alias" (opens Notepad)
  4. Change Alias to WSGIScriptAlias, remove the trailing slash after the relative URL, and change the directory location to point directly to your WSGI file. Simplify the Directory directives. Here's my alias file, api.conf:

    WSGIScriptReloading On
    WSGIScriptAlias /api "c:/path/to/python/application/code/app.wsgi" 
    
    <Directory "c:/path/to/python/application/code">
        Order deny,allow
        Allow from all
    </Directory>
    
  5. Start/restart your Apache service. Python app is now accessible through http://localhost/api/

Comments [0]
The DRM Chair - self-destructs after 8 sittings http://t.co/yI08ZTopa0
Science Says: Nasty Commenters Can Destroy A Website's Brand Over Time | Co.Design http://t.co/lsTeyFGA5l
Survey: 31% of medical practices are dissatisfied enough to switch EHRs http://t.co/xc66aDp5fQ
I wish more design teams would document their projects with @softfacade's inspiring level of detail. http://t.co/GM62kwzHdc
@twbootstrap Honored to have been one of the 7,000 ;) Looking forward to proportional line height in 3.0!
All the talks from last week's W3Conf: http://t.co/hNLGjVfs7E
A Working Draft for the First Episode of Downton Abbey, Season 4 : The New Yorker http://t.co/QLaXg2YyMv
CSS spoiler alert: rem units don't work in IE8 http://t.co/WGNXuEV2
Use Bootstrap alerts as growl notifications: http://t.co/PJQrdRQL
Help! How to open a URL with a hash using Selenium? http://t.co/NXx6CMfE
Access array items by index in a @handlebarsjs template: http://t.co/KtQNpzqZ
"Turn any idea for a feature into a hypothesis that first needs validation from the user." http://t.co/PrVAvoZe
For proper routing, please note your current target country/region and make changes as necessary using the Select target country/region link
I have to say, @lenovo has one of the worst online support experiences I've encountered in a long time.
@lenovo My USB 3 dock started giving terrible video performance, but I can't figure out your support website. Help?
Build interactive HTML U.S. maps with the Stately font http://t.co/LtVRM5jg
'text-wrap: balance" could mean the end to extraneous <br />s http://t.co/gWLINj7F
RT @CoryBooker: Yes, I can tweet out a Dvar Torah if that would help. RT @mjbarash: do you think Hebrew School should be cancelled tomorrow?
This does not inspire confidence... @mailbox http://t.co/BZOLGUdd
@atlassian If I already have an Atlassian ID, why do I need to create yet another account on my Jira On Demand instance?
RT @arbesman: Forget Big Data; it's time to focus on Long Data! My piece in @WiredOpinion http://t.co/FG6KB4pM …