Skip to content

Avalon-Party-Game/avalon-serverless

Repository files navigation

Avalon Serverless Version (Hasura Backend)

This is a new project similar to Avalon Nodejs Ver. Since this version uses Hasura as backend, you can deploy the frontend on any edge runtime (eg. Vercel)

The frontend uses GraphQL subscription to get realtime updates from Hasura server so that we can easily synchronize states across multiple browsers

Screenshot


Deployment pre-request

  • Hasura
  • Node.js 16+
  • pnpm

Prepare

  1. Create a Hasura instance, either from Hasura cloud or self hosted

  2. Install Hasura CLI

  3. Initialize Hasura instance:

    • Change hasura/config.yaml to your hasura endpoint/admin-secret in config.yaml

      version: 3
      endpoint: Your Hasura Endpoint # eg. https://xxx.hasura.app
      admin_secret: Your Hasura Admin Secret
      metadata_directory: metadata
      actions:
          kind: synchronous
          handler_webhook_baseurl: http://localhost:3000
    • Run hasura migration and initialization

      cd ./hasura
      hasura migration apply # apply scheme/db migrations
      hasura metadata apply # apply hasura metadata
      hasura seed apply # apply initial data seed
    • Ensure you have configure HASURA_GRAPHQL_UNAUTHORIZED_ROLE environment variable as player in your hasura cloud dashboard or docker runtime

  4. prepare .env file under workspace root folder for nodejs usage

    uri="Your Hasura GraphQL Endpoint" # without protocol, eg: xxx.hasura.app/v1/graphql
    hasura_admin_secret="Your Hasura Admin Secret"

Development

  • Run dev script

    pnpm i
    pnpm dev
  • Generate GraphQL type

    pnpm gen

Deployment

  • Make sure your environment variables equivalent to .env file is configured in your server runtime

    (eg. Config Environment Variables on Vercel Dashboard)

  • Run script

    pnpm i
    pnpm build
    pnpm start

Todo

  • Internationalization - Currently support Chinese/English