Define request parameter in app.yaml in Google Appengine app

I want to use static files depending on the request parameter. More specifically, I would like to use preliminary images to optimize search engines. Pages are hosted on Google Appengine, so I use app.yaml to identify these URLs.

handlers:
# Consider anything matching a dot static content.
- url: /(.*\..*)$
  static_files: dist/\1
  upload: dist/(.*\..*)$

# Serve snapshots for seo
- url: /?_escaped_fragment_=(.*)
  static_files: dist/snapshots/\1
  upload: dist/(.*)$

# Otherwise let Angular handle it.
- url: /(.*)
  static_files: dist/index.html
  upload: dist/index.html

However, when I get the URL with the request parameter _escaped_fragment_, the last URL handler starts. Can I define request parameters in URLs? If so, what am I doing wrong?

+4
source share
2 answers

, , , app.yaml.

+4

. , App Engine ... .

import webapp2, urllib, logging, json, os

dp = os.path.dirname(os.path.realpath(__file__))
fp = os.path.join(dp, "resources", 'index.html')
w = open(fp, 'r').read()

class Fragment(webapp2.RequestHandler):
  def get(self, pathname):
    if '_escaped_fragment_' in self.request.arguments():
      CODE_GOES_HERE_FOR_BUILDING_YOUR_FRAGMENT_RESPONSE
    else:
      self.response.write(w)

application = webapp2.WSGIApplication(
    [('/(.*)', Fragment)],
  debug=True)

, _escaped_fragment_ . , ( ), index.html static_files: app.yaml.

0

Source: https://habr.com/ru/post/1528771/


All Articles