Giter Site home page Giter Site logo

muhelen / selene-bananas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jacobpatterson1549/selene-bananas

0.0 0.0 0.0 2.51 MB

a tile-based word-forming game

Home Page: https://selene-bananas.herokuapp.com

License: MIT License

JavaScript 0.32% Go 95.92% CSS 0.37% Makefile 0.75% HTML 2.33% PLpgSQL 0.19% Dockerfile 0.11%

selene-bananas's Introduction

selene-bananas

Docker Image CI Go Report Card GoDoc

A Banagrams clone

A tile-based word-forming game based on the popular Banagrams game. https://bananagrams.com/games/bananagrams

With WebSockets, users can play a word game together over a network.

Uses WebAssembly to manage browser logic.

Screenshot

selene-bananas screenshot

Dependencies

New dependencies are automatically added to go.mod when the project is built.

  • pq provides the Postgres driver for storing user passwords and points
  • Gorilla WebSocket are used for bidirectional communication between users and the server
  • jwt is used for stateless web sessions
  • crypto is used to encrypt passwords with bcrypt
  • Font-Awesome provides the "copyright", "github," "linkedin", and "gavel" icons on the about page; they were copied from version 5.13.0 to resources/template/fa.

Build

Running the application

  • Run make serve to build and run the application.

  • Run make serve-tcp to build and run on port 80 for HTTP and port 443 for HTTPS (default TCP ports). Using these ports requires sudo (root) access.

Build dependencies

Go 1.18 is used to build the application.

Make is used to by Makefile to build and runs the application. Run make without any arguments to build the server with the client and other resources embedded in it. This will likely need to be done before using an IDE in order to generate some files and populate the embedded filesystem used by the the server.

Aspell is used to generate the en_US dictionary to validate words on player boards.

  • Note: An integration test depends on aspell-en 2020.12.07-0. This version is used by Docker. Follow the steps below to install the version on your computer:
    1. Download https://ftp.gnu.org/gnu/aspell/dict/en/aspell6-en-2020.12.07-0.tar.bz2
    2. unzip the archive with tar -xf aspell6-en-2020.12.07-0.tar.bz2
    3. configure and install it:
    cd aspell6-en-2020.12.07-0
    ./configure
    make
    sudo make install
    

Node is needed to run WebAssembly tests.

Docker

Launching the application with Docker requires minimal configuration.

  1. Install docker-compose
  2. Set environment variables in the .env file in project root (next to Dockerfile).
    PORT=8000
    NO_TLS_REDIRECT=true
    HTTP_PORT=8001
    HTTPS_PORT=8000
    
    DATABASE_URL=postgres://selene:[email protected]:5432/selene_bananas_db
    POSTGRES_DB=selene_bananas_db
    POSTGRES_USER=selene
    POSTGRES_PASSWORD=selene123
    POSTGRES_PORT=54320
    
  3. Run docker-compose up --build to launch the application, rebuilding parts of it that are stale.
  4. Access application by opening http://127.0.0.1:8000. TLS certificates will be copied to Docker. Environment variables are used from the .env file.

Environment Configuration

Environment variables in the .env file are needed to customize the server.

Minimal config:

DATABASE_URL=postgres://selene:[email protected]:54320/selene_bananas_db?sslmode=disable
PORT=8000
NO_TLS_REDIRECT=true

For development, set CACHE_SECONDS to 0 to not cache static and template resources.

Database

The app stores user information in a Postgresql database. When the app starts, files in the resources/sql folder are run to ensure database objects functions are fresh.

localhost

A Postgresql database can be created with the command below. Change the PGUSER and PGPASSWORD variables. The command requires administrator access.

PGDATABASE="selene_bananas_db" \
PGUSER="selene" \
PGPASSWORD="selene123" \
PGHOSTADDR="127.0.0.1" \
PGPORT="5432" \
sh -c ' \
sudo -u postgres psql \
-c "CREATE DATABASE $PGDATABASE" \
-c "CREATE USER $PGUSER WITH ENCRYPTED PASSWORD '"'"'$PGPASSWORD'"'"'" \
-c "GRANT ALL PRIVILEGES ON DATABASE $PGDATABASE TO $PGUSER" \
&& echo DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@$PGHOSTADDR:$PGPORT/$PGDATABASE'

HTTPS

The app can be run on HTTP over TLS (HTTPS). If running on TLS, most HTTP requests are redirected to HTTPS.

If the server handles HTTPS by providing its own certificate, use the PORT variable to specify the HTTPS port. When POST is defined, no HTTP server will be started from HTTP_PORT and certificates are not read. Use this in combination weth NO_TLS_REDIRECT=true to prevent the server trying to check the TLS headers on requests.

Mkcert

Use mkcert to configure a development machine to accept local certificates.

go get github.com/FiloSottile/mkcert
mkcert -install

Generate certificates for localhost at 127.0.0.1

mkcert 127.0.0.1

Then, replace the resources/tls-cert.pem and resources/tls-key.pem files with the certificates. Update the .env file with the parameters below. Make sure to remove the PORT variable, if present.

HTTP_PORT=8001
HTTPS_PORT=8000
ACME

The server can verify its identity over HTTP to pass a Automatic Certificate Management Environment (ACME) HTTP-01 challenge. Using a local certificate generated in the previous step by mkcert, add the ACME environment parameters listed below with necessary values to the .env file. This makes the HTTP server respond to challenge requests correctly. After the certificates are created, remove the ACME_* parameter and replace the resources/tls-cert.pem and resources/tls-key.pem files with the certificates. See letsencrypt.org for more information about challenges.

ACME_CHALLENGE_TOKEN=token123
ACME_CHALLENGE_KEY=s3cr3t_key

selene-bananas's People

Contributors

jacobpatterson1549 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.