Git Product home page Git Product logo

heroku-aiohttp-web's Introduction

Heroku aiohttp Web Template

An opinionated project template for deploying an aiohttp web app to Heroku, designed to encourage the rapid development and deployment of real-time front-end features.

NB: This template currently tracks an out-of-date version of aiohttp. Please tread carefully. Contributions are welcome to bring it up-to-date.

Launch the app

Use this button:

Deploy

Or alternatively:

$ git clone https://github.com/sseg/heroku-aiohttp-web.git
$ cd heroku-aiohttp-web
$ heroku create
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git
$ heroku config:set ROOT_LOG_LEVEL=INFO
$ git push heroku master

Develop locally

Make sure you have:

Install the project packages:

$ pip install -r dev-requirements.txt
$ pip-sync
$ npm install -g brunch
$ npm install

Then run the project with development asset server:

$ chmod +x ./dev_start.sh `# run this just once`
$ ./dev_start.sh

Or run the app using compiled assets with the Procfile:

$ npm run clean && npm run build:prod
$ heroku local

Local config values are defined in the .env file, and invoked when you start the application using heroku local.

Run the tests

There are no tests yet... but stay tuned!

Application structure

Handlers

aiohttp dispatches requests to handlers which can be either coroutines or functions that accept a Request and return a Response. A base class aiohttp.web.View is also provided to help organize handlers into classes, which provides the convenience of automatically creating an OPTIONS method.

Templates

This app uses jinja2 templates to construct its index view. Template files are kept in the web/templates directory and compiled by the aiohttp_jinja2 renderer. You might prefer mako for templates, or something else—connecting a new renderer to your handlers is easy.

Static files

Javascript and CSS source files are defined in the assets/js and assets/css directories, respectively. These assets are compiled by brunch to the top-level public directory (configuration in brunch-config.js). You might want to add React or Elm compilation which is as simple as installing a new brunch plugin. In development you can run a file watcher with an HTTP + pushstate server to reload your page on file changes (this is started with the dev_start.sh script).

Production asset delivery

In production the assets are compiled once (triggered during Heroku deployment by package.json's postinstall directive). Based on the Python configuration the compiled assets are served through aiohttp (with the piping handled by web.utils.assets.AssetManager).

NB: the aiohttp server is not designed to serve static files, and allowing it to serve production asset traffic will detrimentally affect your application's performance. You will either want to expose this application behind a content delivery proxy (e.g. Cloudflare) or reconfigure it to serve assets from a separate assets server. The brunch asset compiler is configured here to append checksum digests to asset filenames which facilitates cache eviction in these scenarios.

Configuration

This application uses a configuration base file, config/web.yml, which defines defaults and wraps environment variables. New configuration settings should be added to this file and refer to new environment variables. For more information on Heroku app configuration see the devcenter docs.

Contributions

Contributions are welcome! Bugs, feature requests, and unanswered questions can be reported in the Github issue tracker here. Fixes, enhancements, and suggestions are also gratefully accepted in pull requests.

heroku-aiohttp-web's People

Contributors

sseg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

heroku-aiohttp-web's Issues

aiohttp version is out-of-date

The aiohttp project continues to develop at a breakneck pace (version 3.0.9 at this time) but this repository only provides an out-of-date example for version 1.0.1. This makes it hard to continue developing from the template since the framework's documentation no longer matches this application.

A branch of this template should be cut for aiohttp versions 1.x and master should be refactored to work with the later major version series.

App is no longer working (wrong worker class)

App template is no longer working in the current Heroku environment.
According to aiohttp documentation, the Procfile should be changed in order to use a dedicated worker class:

web: gunicorn web:main --worker-class aiohttp.worker.GunicornWebWorker --config config/gunicorn.conf

The default worker generates a weird error message:

aiohttp TypeError: __call__() takes 1 positional argument but 3 were given

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.