Giter VIP home page Giter VIP logo

smorballbeanstalk-backend's Introduction

Backend for Smorball & Beanstalk

This project uses Node.js and MongoDB to create a OCR correction database/server for use with the HTML5 games Smorball and Beanstalk.

Contents

Installation

First, you will need to install MongoDB and Node.js. Note that Node can be acquired through nvm or as a direct download. We recommend using nvm for ease of maintenance.

Clone the project to your system.

$ git clone https://github.com/tiltfactor/SmorballBeanstalk-Backend.git

Copy the example configuration file to config.js.

$ cd SmorballBeanstalk-Backend
$ cp config/config_EXAMPLE.js config/config.js

Now add a string to be used as the secret key on the line indicated. (An example of a good key would be a randomly-generated 32-character string.) This will be used to generate the tokens included in any requests to the database.

Next, install the Node.js dependencies.

$ npm install

Once those dependencies are installed, start MongoDB. You may specify a custom database location inline, or include it in a configuration file. More information about configuring MongoDB can be found here.

# specify database inline
$ mongod --dbpath path/to/db

# if you have created a MongoDB config file, run this instead
$ mongod --config path/to/config

Finally, start node. You should see the following output.

$ npm start

> [email protected] start /.../SmorballBeanstalk-Backend
> node server.js

.../SmorballBeanstalk-Backend/routes/AToken.js
.../SmorballBeanstalk-Backend/routes/bookRoute.js
.../SmorballBeanstalk-Backend/routes/differenceRoute.js
.../SmorballBeanstalk-Backend/routes/pageRoute.js
Started on: 8081

By default the server is started on port 8081 and the endpoints are defined under ~/SmorballBeanstalk-Backend/routes/. You can modify settings in the config.js file.

To verify that the server is running, you can point your web browser to port 8081 of the server (in the case of a local server, copy localhost:8081 into your address bar). You should get the message, "Hello did you get lost?"

Authorization

All endpoints require a jwt token to function. To generate a token, run tokenGen.js:

$ cd SmorballBeanstalk-Backend
$ node tokenGen.js
:Subject

Enter a token when prompted by ":Subject". Valid token subjects are 'Tiltfactor', 'BHL', and 'Game'. Any pre-existing token will be replaced.

{ __v: 0,
  iat: 1432236887475,
  subject: 'Tiltfactor',
  token: <tokenstring>
  _id: 555e335728ad5e17321ac376 }

The token is the token field in the generated object. When making requests, tokens can be included either as a query param under access_token or a header under x-access-token.

Persistence

PM2 is a production process manager for Node.js / io.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. The following commands will install PM2 globally (-g) and use it to run the Node.js server.

$ cd SmorballBeanstalk-Backend
$ npm install pm2 -g
$ pm2 start server.js -i max

More documentation

smorballbeanstalk-backend's People

Contributors

ssolbeck avatar mcsooks avatar

Stargazers

Michael Corrado 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.