diff --git a/README.md b/README.md index 8a191d83..5afe063b 100644 --- a/README.md +++ b/README.md @@ -207,8 +207,31 @@ $ node_modules/.bin/babel-node src/scripts/fetchStatsFromGA.js ### Pulling administrative commands from Google Pub/Sub +#### Setup + +Please use the following command to set up the Pub/Sub topic and subscription, with a Google cloud account with sufficient permissions: + +``` +# Setup ADMIN_PUBSUB_TOPIC +# You can change topic to your need. +export ADMIN_PUBSUB_TOPIC=rumors-api-commands + +# Create a Pub/Sub topic +gcloud pubsub topics create $ADMIN_PUBSUB_TOPIC --schema=${} + +# Create a Pub/Sub subscription +gcloud pubsub subscriptions create ${ADMIN_PUBSUB_TOPIC}-subscription --topic=${ADMIN_PUBSUB_TOPIC} +``` + +Remember to update `ADMIN_PUBSUB_TOPIC` in `.env` and in runtime environment. + +#### Runtime config + When API server starts up, it will link to Google Pub/Sub topic if and only if env var `ADMIN_PUBSUB_TOPIC` is set, using [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials). +The service account behind the key in previous step should have the following [minimum roles](https://cloud.google.com/pubsub/docs/access-control#iam_roles): + - `Pub/Sub Subscriber` on the GCP project + ### Removing article-reply from database - To set an article-reply to deleted state on production, run: ``` diff --git a/src/commandListener.ts b/src/commandListener.ts index b14894e5..3ab62545 100644 --- a/src/commandListener.ts +++ b/src/commandListener.ts @@ -1,3 +1,14 @@ -type T = { foo: number }; +async function main() { + if (!process.env.ADMIN_PUBSUB_TOPIC) { + console.info( + '[command-listener] `ADMIN_PUBSUB_TOPIC` is not set, exiting...' + ); + process.exit(0); + } -console.log('commandServer.ts'); + /** + * Subscribe to specified topics + */ +} + +main().catch(err => console.error('[command-listener]', err)); diff --git a/tsconfig.json b/tsconfig.json index 3cb046ba..bdab40b0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "noEmit": true, "esModuleInterop": true, "module": "esnext", + "target": "ESNext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true