Skip to content

thinkful-ei-rabbit/capstone-three-server-team-b

Repository files navigation

Go Fish Server!

Here's the backend which serves our Go Fish Game Application! The backend manages endpoints that use CRUD methods. You can learn more about the Front End code here

Table of Contents

API Documentation

All Endpoints

-- /api/users -- /api/auth

JWT Auth

  • POST request made to /api/auth/login
  • The body of the request consists of:
{
  email: '',
  password: ''
}

Additional Endpoints

(e.g. registering, playing the game)

  • POST request made to /api/users
  • The body of the request consists of:
{
    "playerName": " ", // requires a unique username, so other users cannot already have that username
    "email": " ", // requires @email.com formatting
    "password": " " // requires 1 uppercase, 1 lowercase, 1 special character and a number
}
  • socket.on('connection', () => {}) establishes a server connection, in which event listeners can be tied
  • At the start of the game users join the server:
{
   socket.on('joinServer', (userObj) => {


    // define socket identity info before join
        socket.nickname = userObj.playerName;
        socket.roomNumber = userObj.room;
        socket.player_id = userObj.user_id;
    //  NOTE: socket.id is auto generated
    if (ServerRooms.activeRooms[socket.roomNumber]) {
      if (ServerRooms.activeRooms[socket.roomNumber].started === true) {
        return socket.emit('server join denial');
      }
    }
}
  • socket.emit('example', {userInfo}) sends an 'example' event with the object containing userInfo.
  • For example, when a player asks another player for a card:
{
    io.to(socket.roomNumber).emit('messageResponse', {
      user: 'Server Message',
      value: `${asker.name} is asking  ${requested.requestedName} for a ${rankReq}.`,
    });
}

We use Socket.io to send a 'messageResponse' event with an object containing data about user actions in the game. io.to(some-room-id).emit('example') sends a message to all users in that room, configured in Socket.io

Tech Stack

Back End

  • Node and Express
    • Authentication using JWT
    • RESTful Api
  • Socket.io

Testing

  • Supertest (integration)
  • Mocha and Chai (unit)

Database

  • Postgres
  • Knex.js - SQL wrapper

Production

  • Deployed via Heroku

Set up

Complete the following steps to start a new project (NEW-PROJECT-NAME):

  1. Clone this repository to your local machine git clone capstone-three-server-team-b
  2. cd into the cloned repository
  3. Make a fresh start of the git history for this project with rm -rf .git && git init
  4. Install the node dependencies npm install
  5. Create an .env that will be ignored by git and read by the express server touch .env
  6. Edit the contents of the package.json to use NEW-PROJECT-NAME instead of "name": "go-fish-server",

Client Side Setup

Follow the setup instructions to get Go Fish Client up and running.

Scripts to get started

Start the application npm start

Start nodemon for the application npm run dev

Run the tests npm test

Deploying

When your new project is ready for deployment, add a new Heroku application with heroku create. This will make a new git remote called "heroku" and you can then npm run deploy which will push to this remote's master branch.

Upcoming Features

  • Returning users can view and edit their profile
  • All users can view the leaderboard

About the Devs

-Caleb Jackson -Harry Winkler -Jason Stankevich -Malik DeJean -Michael Sliger

Special Thanks

To Thinkful's Engineering Immersion Course TAs, instructors and mentors!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •