Giter VIP home page Giter VIP logo

ballboy_server's Introduction

Build Status Greenkeeper badge Maintainability Test Coverage

Getting Started

1. Setup MongoDB provider

Before doing anything, we need to setup a Mongo provider to hold our database for us. I'll describe two ways of doing this; choose the one you like the most.

Install Mongo locally

The first approach is to install Mongo locally. In order to so, go to https://docs.mongodb.com/manual/administration/install-community/ and follow the instructions based on your operating system. After that, open a new terminal and start the mongo service; in my case, I'm on Ubuntu, so I run sudo service mongod start. This will start the Mongo service in the background on port 27017.

Get a Sandbox Mongo instance on mLab

The second option is to create a FREE database hosted on mLab and then connect your application to the remote instance. To do so, go to mLab and create a sandbox Mongo instance. Then, go to the Users tab in your mLab-sandbox-MongoDB-instance-dashboard and click on the 'add a database user' button; setup username and password. Remember those values, we'll need them shortly!

2. Environment variables

At the root directory, copy the file called .sample.env and rename it into .env.

Register the app on Mailgun (you can use any other email provider):

Mailgun allows you to send emails from your app.

In order to get started, first access your Mailgun account. Then, grab your sandbox domain smtp username and password and copy said values into your .env file. Finally, add your email address to the list of Auhtorized Recipients.

Cloudinary

Follow the instructions on the React Native repo to set the following env variables: CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET and CLOUDINARY_CLOUDNAME. Notice CLOUDINARY_UPLOAD_PRESET=default should be kept unchanged.

Sentry (error tracking service API)

  • Visit https://sentry.io and create an account and a new 'Organization' (you can use the same organization as the client app).
  • Set SENTRY_DSN_SERVER env var by creating a new 'Express' project and getting the DSN key.

3. Running the app locally in dev mode

Once we have our Mongo provider, these are the next steps that we need to follow to run the app locally in dev mode:

  1. Inside you project's directory, clone the project and move to the project's folder
>> cd bb (project folder's name)
>> git clone [email protected]:fede-rodes/ballboy_server.git server
>> cd server
  1. Setup your MONGO_URL env variable inside .env to connect the app with your recently created Mongo instance. In case you are using mLab, remember to use your credentials. In case your are running mongo locally, you can use the default value for MONGO_URL.

  2. Install project dependencies, and run the app locally.

>> yarn install
>> yarn start

The server should be running on port 3001 --> http://localhost:3001 The GraphQL playground should be running on http://localhost:3001/graphql (only accessible in dev mode).

4. Running the app locally in production mode

  1. Follow the steps above to setup your Mongo service.

  2. Install heroku cli: https://devcenter.heroku.com/articles/heroku-cli

  3. Clone the project and move to the project's folder

>> cd bb (project folder's name)
>> git clone [email protected]:fede-rodes/ballboy_server.git server
>> cd server
  1. Setup your MONGO_URL env variable as describe above.

  2. Install dependencies and run the app locally in production mode.

>> yarn install && yarn build
>> heroku local

This should launch the server on port 5000 --> http://localhost:5000. As far as I understand, the port (process.env.PORT) is setup by heroku and can't be changed.

5. Deploy to heroku

  1. Follow the steps above to setup a Mongo service on mLab.

  2. Install heroku cli: https://devcenter.heroku.com/articles/heroku-cli

  3. Clone the project and move to the project's folder

>> cd bb (project folder's name)
>> git clone [email protected]:fede-rodes/ballboy_server.git server
>> cd server
  1. Initiate Heroku cli and create a new app
>> heroku login (enter your credentials)
>> heroku create <YOUR_APP_NAME>
  1. Set MONGO_URL env variable.
heroku config:set MONGO_URL=mongodb://<dbuser>:<dbpassword>@<something>.mlab.com:<port>/<dbname>
  1. Push the code to Heroku.
>> git push heroku master

Comment: if you want to deploy from a branch different than master run:

>> git push heroku <BRANCH_NAME>:master

6. Heroku deploy troubleshooting

In case your build fails with an error /bin/sh: 1: <SOME-DEP>: not found and you are building the project with yarn, try setting the following env variable:

heroku config:set NPM_CONFIG_PRODUCTION=false

Set app name:

heroku apps:<SOME_COMMAND> --app <APP_NAME>

Source: https://devcenter.heroku.com/articles/using-the-cli

Set a FREE dyno:

heroku ps:scale web=1 --app <APP_NAME>

Further reading

GraphQL / Apollo

Testing

Auth

Deployment / Heroku

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.