How can I only serve statistics files in Google App Engine?

I wrote a game with HTML5. Locally, it only works at startup:

python -m SimpleHTTPServer

      

And then open localhost:8000

. So just .html and .js files won't work. I want to put my game online and because of this Github (Pages) is out of the question, because it won't work.

This is the part of the code for which I need a server (I understand that localhost:8000/res/

won't work in App Engine, I will need to change the address):

var mapFile = new XMLHttpRequest();
var self = this;
mapFile.open("GET", "http://localhost:8000/res/map" + mapNumber.toString() + ".txt", true);

mapFile.onreadystatechange = function() {
  if (mapFile.readyState === 4) {
    if (mapFile.status === 200) {
      self.lines = mapFile.responseText.split("\n");
      self.loadTilesFromLines();
    }
  }
};

mapFile.send(null);

      

So I heard that Google App Engine will work, it supports Python and is very popular. Now I don't need something like what they have in the documentation (which is well written):

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, webapp2 World!')

app = webapp2.WSGIApplication([('/', MainPage)],
                              debug=True)

      

All I need is SimpleHTTPServer, which allows me to open mine index.html

on my-app.appspot.com

.

I tried this example and run it, but I can't get my browser to open index.html

or src/

or even res/

.

So, I'm not even sure if Google App Engine supports what I'm trying to achieve here. The documentation just focuses on building apps that use Python, and all I needed with Python was SimpleHTTPServer, which I don't think I need with App Engine.

+3


source to share


1 answer


Yes, it is very convenient for what you are trying to achieve here. Since you just want to serve static files, this is very easy and you don't need to include any Python code.

Let's assume you have the following structure:

└── my-game
    ├── app.yaml
    └── static
        ├── index.html
        ├── js
        │   └── script.js
        └── res
            └── map.txt

      

This one app.yaml

should look like this:

application: my-app
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:

- url: /
  static_files: static/index.html
  upload: static/index.html

- url: /
  static_dir: static/

      



After you are about to install the Google App Engine SDK (if you haven't already), you should be able to run the command dev_appserver.py

from your terminal. If you have the above structure, try running it using the following:

$ dev_appserver.py /path/to/my-game

      

If everything goes smoothly, you can see your index.html

on http://localhost:8080

, map.txt

on http://localhost:8080/res/map.txt

, and you can figure out the rest.

Note that you can still run the application using python -m SimpleHTTPServer

from the catalog static

and test it against localhost:8000

.

+3


source







All Articles