add following handler cloud run service

This commit is contained in:
Hongbo Wu 2023-11-08 15:23:49 +08:00
parent cbb5a0a921
commit 4bef0a006a
11 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1,5 @@
node_modules
build
.env*
Dockerfile
.dockerignore

View file

@ -0,0 +1,2 @@
node_modules/
build/

View file

@ -0,0 +1,6 @@
{
"extends": "../../.eslintrc",
"parserOptions": {
"project": "tsconfig.json"
}
}

View file

@ -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

View file

@ -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"]

View file

@ -0,0 +1,5 @@
{
"extension": ["ts"],
"spec": "test/**/*.test.ts",
"require": "test/babel-register.js"
}

View file

@ -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"
}
}

View file

@ -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')
}
)

View file

@ -0,0 +1,3 @@
const register = require('@babel/register').default
register({ extensions: ['.ts', '.tsx', '.js', '.jsx'] })

View file

@ -0,0 +1,8 @@
import { expect } from 'chai'
import 'mocha'
describe('stub test', () => {
it('should pass', () => {
expect(true).to.be.true
})
})

View file

@ -0,0 +1,8 @@
{
"extends": "./../../tsconfig.json",
"compilerOptions": {
"outDir": "build",
"rootDir": "."
},
"include": ["src"]
}