Skip to content

Commit 5249f89

Browse files
authored
Merge pull request #311 from canihavesomecoffee/patch-1
Improve README
2 parents 040b515 + 8a1c654 commit 5249f89

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
1-
# beacon-backend
1+
# CCExtractor Beacon back-end
22

3-
This is the backend for the beacon app. It is written in GraphQL using Apollo and has realtime subscriptions to share user locations with one another. A MongoDB Atlas cluster is used for databasing. You can create your own and put the connection string in the .env file.
3+
This is the backend for the Beacon app. It is written in GraphQL using Apollo and has realtime subscriptions to share user locations with one another. A MongoDB Atlas cluster is used for databasing.
44

5-
`master` contains all the queries, mutations and subscriptions together for running on a standalone server. The `aws` branch has been modified to run the API on AWS Lambda which is a serverless platform so no resources are used while idle. This means subscriptions cannot be run since it is serverless, so we have another `manager` function that starts an ec2 instance while a beacon is active since that is only when subscriptions are necessary, and it pauses the ec2 instance when there is no beacon running. To communicate across Lambda and ec2, redis is used for the pub/sub mechanism.
5+
## Live URL's (possibly outdated)
6+
7+
- `https://beacon.aadibajpai.com`: standalone version for development and testing;
8+
- `https://agw4au70ek.execute-api.us-east-1.amazonaws.com/dev/` for production use
9+
10+
## Deployment
611

7-
The `serverless` framework is used for the Lambda deploys.
12+
### Set up MongoDB
813

9-
The standalone version of the running API may be found at `https://beacon.aadibajpai.com` which is for development and testing, while the production Lambda is at `https://agw4au70ek.execute-api.us-east-1.amazonaws.com/dev/` and the ec2 instance is found at `shouldwealiastheiptosomething`.
14+
Through cloud.mongodb.com you can set up a (free) instance of MongoDB to store all data.
1015

11-
to set up:
16+
While creating a database, make sure you do the following things:
17+
- Write down the username/password combination after adding the user (through the quick-configuration).
18+
- Allow all IP's to access the database (use `0.0.0.0/0`for this); FIXME (unsecure)
19+
20+
Once created, you can get the full URI by clicking "Connect", then select "Connect your application". The URI should look something like "mongodb+srv://<user>:<password>@<db-name>.mongodb.net/?retryWrites=true&w=majority". This URI should be stored in the `DB` variable of your `.env` file.
21+
22+
### Running on AWS Lambda (serverless)
23+
24+
```
25+
# Install serverless and plugins needed
26+
npm install -g serverless
27+
serverless plugin install -n serverless-offline
28+
# Copy the .env and update it accordingly
29+
cp .env.example .env
30+
nano .env
31+
# Things you should have set up: DB (see above, "Set up MongoDB"), JWT_SECRET (random string)
32+
# Run the install script
33+
./script.sh "{acess key here}" "{secret key here}" {dev or prod here}
34+
```
35+
36+
### Running locally
1237

1338
- clone the repo
1439
- copy .env.sample to .env and fill variables then run:
@@ -18,6 +43,8 @@ npm i
1843
npm start
1944
```
2045

21-
for the serverless stuff, your .env file will be populated to the functions so you only need to do `serverless deploy`, once you have it installed.
46+
### Old ramblings
47+
48+
`master` contains all the queries, mutations and subscriptions together for running on a standalone server. The `aws` branch has been modified to run the API on AWS Lambda which is a serverless platform so no resources are used while idle. This means subscriptions cannot be run since it is serverless, so we have another `manager` function that starts an ec2 instance while a beacon is active since that is only when subscriptions are necessary, and it pauses the ec2 instance when there is no beacon running. To communicate across Lambda and ec2, redis is used for the pub/sub mechanism.
2249

2350
for the ec2 instance, you would want to deploy the normal `master` branch to a server and set up a cron job or similar that would start the service when the instance is started after it was paused

0 commit comments

Comments
 (0)