Regis Frey
Regis Frey

Reputation: 888

App Engine regex issues directing URL to script and handlers

I am trying to break my app into separate scripts. Part of this effort meant breaking the api calls into it's own file. However the calls to the api (like http://example.com/api/game/new no longer work). My app.yaml contains this:

- url: /api.*
  script: api.py

which seems to be redirecting properly because this configuration works:

def main():
    application = webapp.WSGIApplication([('/.*', TestPage)], debug=True)
    util.run_wsgi_app(application)

however this one doesn't:

def main():
    application = webapp.WSGIApplication([('/game/new$', CreateGame), 
                                          ('/game/(d+)$', GameHandler)],
                                          debug=True)
    util.run_wsgi_app(application)

Upvotes: 1

Views: 1491

Answers (2)

misterte
misterte

Reputation: 997

My guess is you are trying to pass some arguments to your handler.

Try this. It will give you a hint.

#!/usr/bin/env python

import wsgiref.handlers
from google.appengine.ext import webapp


class MyHandler(webapp.RequestHandler):
    def get(self, string=None):
        if string:
            self.response.out.write("Hello World!! %s" % string)
        else:
            self.response.out.write("Hello World!! (and no word)")


def main():
    app = webapp.WSGIApplication([
                    (r'/word/(\w+)/?$', MyHandler),
                    (r'.*', MyHandler),
                    ], debug=True)

    wsgiref.handlers.CGIHandler().run(app)


if __name__ == "__main__":
    main()

Hope it helps. Cheers.

Upvotes: 2

Nick Johnson
Nick Johnson

Reputation: 101149

The URL patterns you use in the WSGI application have to be the full path - eg, /api/game/.... The App Engine infrastructure uses the regular expressions in app.yaml to route requests, but it does not modify the request path based on them.

Upvotes: 3

Related Questions