diff --git a/packages/following-handler/.dockerignore b/packages/following-handler/.dockerignore new file mode 100644 index 000000000..d8aea4ee6 --- /dev/null +++ b/packages/following-handler/.dockerignore @@ -0,0 +1,5 @@ +node_modules +build +.env* +Dockerfile +.dockerignore diff --git a/packages/following-handler/.eslintignore b/packages/following-handler/.eslintignore new file mode 100644 index 000000000..b38db2f29 --- /dev/null +++ b/packages/following-handler/.eslintignore @@ -0,0 +1,2 @@ +node_modules/ +build/ diff --git a/packages/following-handler/.eslintrc b/packages/following-handler/.eslintrc new file mode 100644 index 000000000..e006282a6 --- /dev/null +++ b/packages/following-handler/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "../../.eslintrc", + "parserOptions": { + "project": "tsconfig.json" + } +} \ No newline at end of file diff --git a/packages/following-handler/.gcloudignore b/packages/following-handler/.gcloudignore new file mode 100644 index 000000000..ccc4eb240 --- /dev/null +++ b/packages/following-handler/.gcloudignore @@ -0,0 +1,16 @@ +# This file specifies files that are *not* uploaded to Google Cloud Platform +# using gcloud. It follows the same syntax as .gitignore, with the addition of +# "#!include" directives (which insert the entries of the given .gitignore-style +# file at that point). +# +# For more information, run: +# $ gcloud topic gcloudignore +# +.gcloudignore +# If you would like to upload your .git directory, .gitignore file or files +# from your .gitignore file, remove the corresponding line +# below: +.git +.gitignore + +node_modules diff --git a/packages/following-handler/Dockerfile b/packages/following-handler/Dockerfile new file mode 100644 index 000000000..85974823e --- /dev/null +++ b/packages/following-handler/Dockerfile @@ -0,0 +1,26 @@ +FROM node:18.16-alpine + +# Run everything after as non-privileged user. +WORKDIR /app + +COPY package.json . +COPY yarn.lock . +COPY tsconfig.json . +COPY .eslintrc . + +COPY /packages/following-handler/package.json ./packages/following-handler/package.json + +RUN yarn install --pure-lockfile + +COPY /packages/following-handler ./packages/following-handler +RUN yarn workspace @omnivore/rss-handler build + +# After building, fetch the production dependencies +RUN rm -rf /app/packages/following-handler/node_modules +RUN rm -rf /app/node_modules +RUN yarn install --pure-lockfile --production + +EXPOSE 8080 + +CMD ["yarn", "workspace", "@omnivore/following-handler", "start"] + diff --git a/packages/following-handler/mocha-config.json b/packages/following-handler/mocha-config.json new file mode 100644 index 000000000..44d1d24c1 --- /dev/null +++ b/packages/following-handler/mocha-config.json @@ -0,0 +1,5 @@ +{ + "extension": ["ts"], + "spec": "test/**/*.test.ts", + "require": "test/babel-register.js" + } \ No newline at end of file diff --git a/packages/following-handler/package.json b/packages/following-handler/package.json new file mode 100644 index 000000000..895476eea --- /dev/null +++ b/packages/following-handler/package.json @@ -0,0 +1,31 @@ +{ + "name": "@omnivore/following-handler", + "version": "1.0.0", + "main": "build/src/index.js", + "files": [ + "build/src" + ], + "license": "Apache-2.0", + "scripts": { + "test": "yarn mocha -r ts-node/register --config mocha-config.json", + "test:typecheck": "tsc --noEmit", + "lint": "eslint src --ext ts,js,tsx,jsx", + "compile": "tsc", + "build": "tsc", + "start": "functions-framework --target=followingHandler", + "dev": "concurrently \"tsc -w\" \"nodemon --watch ./build/ --exec npm run start\"" + }, + "devDependencies": { + "chai": "^4.3.6", + "eslint-plugin-prettier": "^4.0.0", + "mocha": "^10.0.0" + }, + "dependencies": { + "@google-cloud/functions-framework": "3.1.2", + "@sentry/serverless": "^7.77.0", + "dotenv": "^16.0.1" + }, + "volta": { + "extends": "../../package.json" + } +} diff --git a/packages/following-handler/src/index.ts b/packages/following-handler/src/index.ts new file mode 100644 index 000000000..cbc8e307c --- /dev/null +++ b/packages/following-handler/src/index.ts @@ -0,0 +1,19 @@ +import * as Sentry from '@sentry/serverless' +import * as dotenv from 'dotenv' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import + +dotenv.config() +Sentry.GCPFunction.init({ + dsn: process.env.SENTRY_DSN, + tracesSampleRate: 0, +}) + +export const followingHandler = Sentry.GCPFunction.wrapHttpFunction( + (req, res) => { + if (req.query.token !== process.env.PUBSUB_VERIFICATION_TOKEN) { + console.log('query does not include valid token') + return res.sendStatus(403) + } + + res.send('ok') + } +) diff --git a/packages/following-handler/test/babel-register.js b/packages/following-handler/test/babel-register.js new file mode 100644 index 000000000..a6f65f60a --- /dev/null +++ b/packages/following-handler/test/babel-register.js @@ -0,0 +1,3 @@ +const register = require('@babel/register').default + +register({ extensions: ['.ts', '.tsx', '.js', '.jsx'] }) diff --git a/packages/following-handler/test/stub.test.ts b/packages/following-handler/test/stub.test.ts new file mode 100644 index 000000000..935d1e499 --- /dev/null +++ b/packages/following-handler/test/stub.test.ts @@ -0,0 +1,8 @@ +import { expect } from 'chai' +import 'mocha' + +describe('stub test', () => { + it('should pass', () => { + expect(true).to.be.true + }) +}) diff --git a/packages/following-handler/tsconfig.json b/packages/following-handler/tsconfig.json new file mode 100644 index 000000000..7ebe093f6 --- /dev/null +++ b/packages/following-handler/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "./../../tsconfig.json", + "compilerOptions": { + "outDir": "build", + "rootDir": "." + }, + "include": ["src"] +}