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.
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.
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!
At the root directory, copy the file called .sample.env
and rename it into .env
.
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.
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.
- 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.
Once we have our Mongo provider, these are the next steps that we need to follow to run the app locally in dev mode:
- 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
-
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. -
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).
-
Follow the steps above to setup your Mongo service.
-
Install heroku cli: https://devcenter.heroku.com/articles/heroku-cli
-
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
-
Setup your MONGO_URL env variable as describe above.
-
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.
-
Follow the steps above to setup a Mongo service on mLab.
-
Install heroku cli: https://devcenter.heroku.com/articles/heroku-cli
-
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
- Initiate Heroku cli and create a new app
>> heroku login (enter your credentials)
>> heroku create <YOUR_APP_NAME>
- Set MONGO_URL env variable.
heroku config:set MONGO_URL=mongodb://<dbuser>:<dbpassword>@<something>.mlab.com:<port>/<dbname>
- 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
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>
- https://www.apollographql.com/docs
- https://dev-blog.apollodata.com/full-stack-react-graphql-tutorial-582ac8d24e3b
- https://dev-blog.apollodata.com/react-graphql-tutorial-part-2-server-99d0528c7928
- https://dev-blog.apollodata.com/react-graphql-tutorial-mutations-764d7ec23c15
- https://dev-blog.apollodata.com/tutorial-building-a-graphql-server-cddaa023c035
- https://caveofcode.com/2016/10/apollo-server-using-the-graphql-schema-language/
- https://caveofcode.com/2016/11/the-connector-and-model-layer-in-your-graphql-apollo-server/
- https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/deployment
- https://www.robinwieruch.de
- https://codewithmosh.com/p/the-complete-node-js-course
- https://blog.apollographql.com/authorization-in-graphql-452b1c402a9