Giter Site home page Giter Site logo

niqzart / flask-socketio-example Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14 KB

Short example of a minimal flask-socketio application, that actually works. No compatibility errors, no too old libraries. Config for heroku is in the repo as well.

Home Page: https://flask-socketio-example.herokuapp.com/

HTML 61.70% Python 38.30%
flask flask-application flask-socketio socket-io heroku

flask-socketio-example's Introduction

Flask SocketIO Example

Why?

I haven't found a good described example for that. Ones I found are either too old and use old versions of used libraries (which is not ideal) or don't work because of a version compatibility issue(s). I managed to make it work, but it did take a few hours.

I hope this example will help someone to not waste the same amount of time.

What does it do?

It's a python web server that serves an HTML page with a chat-like interface. You can send messages, which are processed by flask-soketio and broadcasted to everyone connected to the main page.

The example is hosted on heroku, you can visit it and try it out for yourself here. Open up two tabs with it and chat!

A bit on how I will try to make this example future-proof

  1. All requirements are marked as exact versions, so version compatibility shouldn't become a problem
  2. I'm still working on an app with flask-socketio, this repo will be updated from time to time (last update date == last commit date)
  3. If some links go dead, I'll replace them, you can report such links in issues

What should be redone for production environment?

CORS policy. Currently it's allowing any origins, that should never be a thing in a production environment. See flask-socketio documentation for info on CORS configuration

Hot to run it locally?

  1. Clone the repo
  2. Create a virtual python environment (https://docs.python.org/3/library/venv.html)
  3. Open a console & activate the virtual environment
  4. Install requirements: pip install -r requirements.txt
  5. Run the main file: python main.py
  6. Done! Web server should be running at http://localhost:5000/

How to deploy this to heroku?

  1. Clone the repo
  2. Open a console in repo's folder
  3. Create an application on heroku
  4. Login to heroku CLI: heroku login
  5. Attach your heroku app as a git remote: heroku git:remote -a your-app-name-here
  6. Push it to heroku: git push heroku master
  7. Wait for it to deploy, when visit your applications page, and you're done!

Links

flask-socketio-example's People

Contributors

niqzart avatar

Watchers

 avatar

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.