NWSGI - How give URL Pattern?

Jun 13, 2011 at 8:07 PM

Hi,

I'm building Azure application in Ironpython using NWSGI. How do I configure the Web.Config to split the static content url (for css/images/js) from application url? In Web.Config httpHandlers/handlers is there a way to specify a url patern? i.e. all the urls starting with App/1/*/** to be handled by app.wsgi. If I simply give path="*" all my static files requests also hitting the app.wsgi. So how do I handle my static files request like css/images/js?

 

Coordinator
Jun 13, 2011 at 9:18 PM

If you set the handler path to "*.wsgi" (or path="app.wsgi" if you want to be really sure) then only requests for that file should go through NWSGI, and everything else should be handled by IIS.

Jun 14, 2011 at 6:16 AM
Edited Jun 14, 2011 at 6:16 AM

Hi,

Thanks for your reply. I can't give path to "*.wsgi" or "app.wsgi" because none of my application url will be ending with .wsgi. I'm using routing framework inside my app.wsgi to redirect the urls to corresponding controller. So my urls could be like /App/1/sh001/ac001/po001 or /App/1/sh001/ac001/po001/ce002/sh002/li001. Hence I  need to use a pattern not necessarily ending 'wsgi'.

Coordinator
Jun 14, 2011 at 3:39 PM

I thought you might say that :). According to the docs, this is all supported by default on Azure.

The trick here is to still have 'app.wsgi' in the URL, but make it invisible to the user. To do this you'll want to use the URL Rewriter. I don't have the exact syntax (nor a Windows machine to check) handy, but what you'll need to do is create a rule that changes

    http://example.com/App/1/sh001/ac001/po001

into

    http://example.com/app.wsgi/App/1/sh001/ac001/po001

while excluding static files (i.e., add conditions to the rule to exclude /images or /media or whatever from being rewritten). The important thing is that the URL rewriter runs before IIS chooses the handler, so that app requests will go to app.wsgi and the static requests (which aren't rewritten) will go to IIS for speedy handling. Also, the client will never see the second URL - only IIS will.

You might have to change your routing code, since the path will now be in PATH_INFO.

Your app will still generate the URLs you want the client to see, but if for whatever reason a URL escapes with app.wsgi in it, I set up a rule so that http://example.com/app.wsgi/App/1/sh001/ac001/po001 will 301 redirect to http://example.com/App/1/sh001/ac001/po001 (for SEO and all that fun stuff).

I'm pretty sure the URL rewriter module has templates for both of these rules to make it a little easier for you.

Jun 16, 2011 at 2:18 PM

Hi thanks for the info. I figured out the solution in different way I simply gave path="App" in httpHandlers and scriptName="App" so it solves my problem. And its working in NWSGI 2.1. Now my application perfectly working fine.

Coordinator
Jun 16, 2011 at 3:55 PM
Glad to hear that it's working! When your site is launched would mind
sending me a link? I always like to see what people are using NWSGI
for.

Also, would you mind sharing your web.config, or at least the
<httpHandler> and <wsgi> sections? I'm curious has to how you set it
up, because I didn't think it would work that way - if there's a
better way then how I've been doing it, I'd like to know!
Jun 17, 2011 at 10:30 AM

Hi Jeff,

Sure. We are a platform-as-a-service company(OrangeScape) which allows developers to build applications and deploy to any cloud/enterprise platforms. I am working on cross cloud deployment to Azure. As soon as I'm done with this implementation I will be very glad sharing the link as well as complete information about how we implemented it. I really appreciate the support. Thanks.

here is my Web.Config

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="wsgi" type="NWSGI.WsgiSection, NWSGI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=41e64ddc1bf1fc86"/>
  </configSections>

  <wsgi>
    <pythonPaths>
      <path path="~/Lib" />
      <path path="~/external" />
    </pythonPaths>
    <scriptMappings>
      <scriptMapping scriptName="Ap_2" callable="wsgi.application" />
    </scriptMappings>
  </wsgi>
  
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <customErrors mode="Off"/>
    <httpHandlers>
      <add verb="*" path="Ap_2" type="NWSGI.WsgiHandler, NWSGI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=41e64ddc1bf1fc86"/>
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <add name="WsgiHandler" path="Ap_2" verb="*" type="NWSGI.WsgiHandler, NWSGI, Version=2.1.0.0, Culture=neutral, PublicKeyToken=41e64ddc1bf1fc86" resourceType="Unspecified"/>
    </handlers>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>

Sample urls in my app:

/Ap_2/1/signin

/Ap_2/1/Sh0bd261196d3845bea975369116a95d24/Acaeb30724139849b198c9c98c5c7ba42b/Sh0bd261196d3845bea975369116a95d24?mimetype=text/html

-adhi

 

Coordinator
Jun 17, 2011 at 4:37 PM
I honestly had no idea that IIS7 supported extensionless handlers like
that. Too much time on IIS6, I guess. I've made a note to add that as
an example in the docs.

If you're only deploying to Azure, I think you can drop the
<system.web>/<httpHandlers> section, as that's for IIS6 (and IIS7
legacy mode) only. Not a big deal, but one less entry to update.
Coordinator
Jun 17, 2011 at 4:41 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.