Backend for CitrusHack 2021, created using Strapi.
You must have node and yarn installed.
Clone the repository
git clone https://github.com/citrushack/CitrusHack2021Backend.git
cd CitrusHack2021Backend
Follow these steps to configure a local Strapi project to use a MongoDB Atlas free 512 MB account in production. (Please see MongoDB Atlas Documentation if you have any questions.)
- You must have already created your Strapi project using MongoDB.
- You must have already created a free MongoDB Atlas account.
- First you need to
Create a new Project
. - Then click
Build a Cluster
, from the options page:- Choose AWS as your Cloud Provider & Region.
- Select a Region. (Note: some Regions do not have a free tier.)
- In Cluster Tier, select Shared Sandbox, Tier
MO
. - In Cluster Name, name your cluster.
- Click the green
Create Cluster
button. You will get a message that says, "Your cluster is being created..."
- Click the green
+ ADD NEW USER
button:- Enter a
username
. - Enter a
password
. - Under
User Privileges
ensureRead and write to any database
is selected. Then clickAdd User
to save.
- Enter a
-
Click the green
+ ADD IP ADDRESS
- Click
ADD CURRENT IP ADDRESS
or manually enter in an IP address towhitelist
. - Leave a comment to label this IP Address. E.g.
Office
. - Then click the green
Confirm
button. - Delete the
0.0.0.0/0
configuration after testing the connection.
- Click
MongoDB Atlas automatically exposes the database credentials into a single environment variable accessible by your app. To locate it, follow these steps:
- Under
Atlas
in the left-hand, click onClusters
. This should take you to yourcluster
. Next, clickCONNECT
and thenConnect Your Application
. - Under
1. Choose your driver version
, select DRIVER asNode.js
and VERSION as2.2.12 or later
. ::: warning You must useVersion: 2.2.12 or later
. ::: - This should show a Connection String Only similar to this:
mongodb://paulbocuse:<password>@strapi-heroku-shard-00-00-oxxxo.mongodb.net:27017,strapi-heroku-shard-00-01-oxxxo.mongodb.net:27017,strapi-heroku-shard-00-02-oxxxo.mongodb.net:27017/test?ssl=true&replicaSet=Strapi-Heroku-shard-0&authSource=admin&retryWrites=true&w=majority
Now, fill in the details from this string into config/database.js
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'mongoose',
settings: {
host: '' /* '.....-00-00-oxxxo.mongodb.net:27017,....-00-01-oxxxo.mongodb.net:27017,....-00-02-oxxxo.mongodb.net:27017'
all 3 hosts seperated by commas here */ ,
srv: false,
port: 27017,
database: '' /*your database name here */ ,,
username: '' /*your username here */ ,
password: '' /*<password> here*/,
},
options: {
ssl: env.bool('DATABASE_SSL', true),
},
},
},
});
::: warning
Please note the <password>
after your username
. In this example, after mongodb://paulbocuse:
. You will need to replace the <password>
with the password you created earlier for this user in your MongoDB Atlas account.
:::
# Using yarn
yarn install
yarn build
yarn develop
The server should launch at http://localhost:1337.