Friday, 7 December 2012

Google App Engine Uploading Static Html

Google app engine is an is a platform as a service (PaaS) cloud computing platform for developing and hosting web applications in Google-managed data centers. Applications are sandboxed and run across multiple servers. App Engine offers automatic scaling for web applications—as the number of requests increases for an application, App Engine automatically allocates more resources for the web application to handle the additional demand.
                You can serve your app with your own domain with "example.xyz.com" or you can host for free in appspot.com provided for free for first 1 GB of usage. Further usage will be charged as per the subscribed amount of data. Google app engine is supported by three runtime environments python, Java and Go.

App engine includes following features :
  •  dynamic web serving, with full support for common web technologies
  • persistent storage with queries, sorting and transactions
  • automatic scaling and load balancing
  • APIs for authenticating users and sending email using Google Accounts
  • a fully featured local development environment that simulates Google App Engine on your computer
  • task queues for performing work outside of the scope of a web request
  • scheduled tasks for triggering events at specified times and regular intervals
 App Engine's Python runtime environment, you can implement your app using the Python programming language, and run it on an optimized Python interpreter. App Engine includes rich APIs and tools for Python web application development.The App Engine software development kits (SDKs) for Java, Python, and Go each include a web server application that emulates all of the App Engine services on your local computer. Each SDK includes all of the APIs and libraries available on App Engine.

Each SDK also includes a tool to upload your application to App Engine. Once you have created your application's code, static files and configuration files, you run the tool to upload the data. The tool prompts you for your Google account email address and password.

See  GOOGLE APP SDK   for sdk download.

You should use two commands from the sdks

dec_appserver.py - Python development server
       It  includes a web server application you can run on your computer that simulates your application running in the App Engine Python runtime environment.

appcfg.py
       You can use this command to upload new versions of the code, configuration and static files for your app to App Engine.

For Uploading your html application you should create a folder for you application with the name of your application. The folder includes three files app.yaml, a python file and the static file which you need to host on google app engine.

app.yaml is an configuration file which is used to describe which handler should be used to different urls.
The file includes
application: helloworld 
version: 1 
runtime: python27
 api_version: 1 
threadsafe: true
 
handlers:- url: /.*
  script: helloworld.app
 
 
Application is helloworld in this case which is an unique application id which would be assigned when you register your web app in appspot.com for free. Version is the application version, your new updations can be assigned to further new versions.
      Runtime is the version of python you are running in your system. This application is threadsafe so the same instance can handle several simultaneous requests. Threadsafe is an advanced feature and may result in erratic behavior if your application is not specifically designed to be threadsafe.Every request to a URL whose path matches the regular expression /.* (all URLs) should be handled by the app object in the helloworld module. 

For testing you can use development web server command which runs a web server listening on port 8080, you can check in the status typing url http://localhost:8080/

The python file is webapp2 framework which has two parts 
  • one or more RequestHandler classes that process requests and build responses
  • a WSGIApplication instance that routes incoming requests to handlers based on the URL
 import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import Request
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template

class mainh(webapp.RequestHandler):
    def get(self):
              self.response.out.write(template.render("prasanthtimer.html",{}))  
      
def main():
    app = webapp.WSGIApplication([
        (r'.*',mainh)], debug=True)
    wsgiref.handlers.CGIHandler().run(app)


if __name__ == "__main__":
    main()
The static file which you would to upload can be specified as a filenname in double quotes. The html file with javascript will also work for this upload.

Now all the configuration is been done now you can upload the file by the following command:
appcfg.py update helloworld/
Now you can find your application running on
 http://your_app_id.appspot.com
Have fun.....!!!!!!!!!!!!

No comments:

Post a Comment