Skip to main content

Cartesify Backend

Project description

This package is intended to be used with @calindra/cartesify.

import asyncio
import logging
from cartesify_backend import CartesifyBackend, CartesifyOptions
from quart import Quart, request, jsonify
import json


app = Quart(__name__)

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

port = 8383

games = []

@app.route('/health', methods=['GET'])
async def your_endpoint():
    logger.info("Request received on health")
    sender_address = request.headers.get('x-msg_sender')
    response_data = {'games': str(games)}
    logger.info(f'response is {response_data}')
    return jsonify(response_data)

@app.route('/new-game', methods=['POST'])
async def new_game():
    logger.info("Request received on new_game")
    sender_address = request.headers.get('x-msg_sender')
    commit = json.loads(await request.get_json())
    print(f"type of commit {type(commit)}")
    games.append({'player1': sender_address, 'commit1': commit['any']})
    return jsonify({'created': len(games)})

async def main():
    try:
        logger.info(f'Initiating app')

        options = CartesifyOptions(url='', broadcast_advance_requests=False)
        cartesify_app = CartesifyBackend().create_app(options)

        await asyncio.gather(app.run_task(port=port, host='0.0.0.0'), cartesify_app.start())

    except Exception as e:
        print(e)
        logger.error(e)

if __name__ == '__main__':
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cartesify_backend-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file cartesify_backend-1.0.1.tar.gz.

File metadata

  • Download URL: cartesify_backend-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for cartesify_backend-1.0.1.tar.gz
Algorithm Hash digest
SHA256 46cb4f6e235756fa0d1251586169b7dc5f349126f0ab55bc4730296457664092
MD5 b4229a6e6c552b8299f2c278b4dc7827
BLAKE2b-256 0d9621fc981b34474a3dcbd2e0f3b337c006b74c947af7531d3238a84bfa62fc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page