Skip to content

Commit 2cb8125

Browse files
authored
Changes to enable deployment on AWS ec2 and lambda. (#206)
* Changes to enable deployment on AWS ec2 and lambda. 1) ecosystem.config.js is a config file so that environment variables can be passed via pm2 when running on ec2. 2) changes in index.mjs are required so that subscriptions persist and connections dont close. * Update index.js
1 parent ce12b8c commit 2cb8125

File tree

6 files changed

+2661
-225
lines changed

6 files changed

+2661
-225
lines changed

ecosystem.config.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
script: "./index.mjs",
5+
watch: ".",
6+
env: {
7+
DB: "",
8+
JWT_SECRET: "",
9+
REDIS_AUTH: "",
10+
REDIS_USERNAME: "",
11+
REDIS_URL: "",
12+
REDIS_PORT: "",
13+
INSTANCE: "",
14+
},
15+
},
16+
],
17+
18+
deploy: {
19+
production: {
20+
user: "SSH_USERNAME",
21+
host: "SSH_HOSTMACHINE",
22+
ref: "origin/master",
23+
repo: "GIT_REPOSITORY",
24+
path: "DESTINATION_PATH",
25+
"pre-deploy-local": "",
26+
"post-deploy": "npm install && pm2 reload ecosystem.config.js --env production",
27+
"pre-setup": "",
28+
},
29+
},
30+
};

graphql/resolvers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ const resolvers = {
2626
const beacon = await Beacon.findById(id).populate("landmarks leader");
2727
if (!beacon) return new UserInputError("No beacon exists with that id.");
2828
// return error iff user not in beacon
29-
if (beacon.leader.id !== user.id && !beacon.followers.includes(user))
30-
return new Error("User should be a part of beacon");
29+
let flag = false;
30+
for (let i = 0; i < beacon.followers.length; i++)
31+
if (beacon.followers[i].id === user.id) {
32+
flag = true;
33+
break;
34+
}
35+
if (beacon.leader.id !== user.id && !flag) return new Error("User should be a part of beacon");
3136
return beacon;
3237
},
3338
group: async (_parent, { id }, { user }) => {

index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ const server = new ApolloServer({
2424
const user = req?.user ? await User.findById(req.user.sub).populate("beacons") : null;
2525
return { user, pubsub };
2626
},
27+
stopGracePeriodMillis: Infinity,
28+
stopOnTerminationSignals: false,
2729
subscriptions: {
28-
path: "/subscriptions",
30+
path: "/graphql",
31+
keepAlive: 9000,
2932
onConnect: async connectionParams => {
3033
console.log("Client connected");
3134
const authorization = connectionParams["Authorization"];

0 commit comments

Comments
 (0)