Compare commits
75 Commits
05cf66392a
...
renovate/a
Author | SHA1 | Date | |
---|---|---|---|
b3865bf971 | |||
edf96e4e64 | |||
72e3a62236 | |||
ddfbb60b25 | |||
eb116c06cd | |||
74f5832a8a | |||
bde1fc4572 | |||
c0c0a3d5b0 | |||
095f13791a | |||
e8acd3b831 | |||
785eb27452 | |||
57d3aa3266 | |||
c32b0cfd05 | |||
5f7cdbf8d9 | |||
cb03d5aa42 | |||
35cdef1942 | |||
f989feb78b | |||
074f025c44 | |||
8d902a03b9 | |||
f946ca2c5d | |||
1e6ea9d104 | |||
30e7158b7e | |||
49e97bb415 | |||
6003c2436a | |||
6b08b8fc7a | |||
355a76845e | |||
804dc30830 | |||
7134ac0b39 | |||
b80fff586e | |||
417ea7b84d | |||
58645ec2b2 | |||
4a3c26b7fa | |||
4402b42756 | |||
c9ec7f5912 | |||
ea3ad8b898 | |||
b5ba126e7c | |||
6675dc18f1 | |||
5d63563c01 | |||
45603ec02e | |||
cb29f2024f | |||
ebfb12a42d | |||
9001c161d8 | |||
fe97190fab | |||
f51d05283d | |||
39b0a653ed | |||
bca3e284b2 | |||
660d23a2a4 | |||
f237a28c27 | |||
fa54ee276f | |||
074558e084 | |||
df3e9ee1c9 | |||
f54f381ef6 | |||
d47dab453b | |||
743db90a50 | |||
667211d956 | |||
a9f3467a57 | |||
c130cb2be5 | |||
d7a49ca544 | |||
cb99bb2032 | |||
68a10da2a6 | |||
19b73af89d | |||
57841ebd74 | |||
805c74ffc4 | |||
805e698668 | |||
36d07fa8dd | |||
82c1b85c08 | |||
b8669f4128 | |||
2a8269a5d1 | |||
d908a0fce5 | |||
1a2e217bbf | |||
11af27862d | |||
5ee3443086 | |||
e1f288996c | |||
ccc8bb5119 | |||
43919014cc |
24
.dockerignore
Normal file
24
.dockerignore
Normal file
@ -0,0 +1,24 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
1
.env-example
Normal file
1
.env-example
Normal file
@ -0,0 +1 @@
|
||||
INFISICAL_TOKEN=example
|
42
.gitea/workflows/publish.yml
Normal file
42
.gitea/workflows/publish.yml
Normal file
@ -0,0 +1,42 @@
|
||||
name: Publish Docker Images
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-22.04
|
||||
container: fascinated/docker-images:node-pnpm-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Repo
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.REPO_USERNAME }}
|
||||
password: ${{ secrets.REPO_TOKEN }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Build Repo
|
||||
run: pnpm run build
|
||||
|
||||
- name: Build and Push (Node)
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
context: .
|
||||
file: ./apps/node/Dockerfile
|
||||
tags: fascinated/proxy:node-latest
|
||||
|
||||
- name: Build and Push (Proxy)
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
context: .
|
||||
file: ./apps/proxy/Dockerfile
|
||||
tags: fascinated/proxy:proxy-latest
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -34,3 +34,6 @@ yarn-error.log*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# Typescript compilied files
|
||||
dist
|
||||
|
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Docker Node.js Launch",
|
||||
"type": "docker",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "docker-run: debug",
|
||||
"platform": "node",
|
||||
"node": {
|
||||
"package": "${workspaceFolder}/apps/node/package.json",
|
||||
"localRoot": "${workspaceFolder}/apps/node"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
42
.vscode/tasks.json
vendored
Normal file
42
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "docker-build",
|
||||
"label": "docker-build",
|
||||
"platform": "node",
|
||||
"dockerBuild": {
|
||||
"dockerfile": "${workspaceFolder}/apps/node/Dockerfile",
|
||||
"context": "${workspaceFolder}/apps/node",
|
||||
"pull": true
|
||||
},
|
||||
"node": {
|
||||
"package": "${workspaceFolder}/apps/node/package.json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "docker-run",
|
||||
"label": "docker-run: release",
|
||||
"dependsOn": ["docker-build"],
|
||||
"platform": "node",
|
||||
"node": {
|
||||
"package": "${workspaceFolder}/apps/node/package.json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "docker-run",
|
||||
"label": "docker-run: debug",
|
||||
"dependsOn": ["docker-build"],
|
||||
"dockerRun": {
|
||||
"env": {
|
||||
"DEBUG": "*",
|
||||
"NODE_ENV": "development"
|
||||
}
|
||||
},
|
||||
"node": {
|
||||
"package": "${workspaceFolder}/apps/node/package.json",
|
||||
"enableDebugging": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -8,6 +8,11 @@ Go to <https://proxy.fascinated.cc>
|
||||
|
||||
## Development
|
||||
|
||||
Prerequisites:
|
||||
|
||||
- [pnpm](https://pnpm.io/)
|
||||
- [Infiscal](https://secrets.fascinated.cc)
|
||||
|
||||
1. Create an Infiscal account at <https://secrets.fascinated.cc>
|
||||
2. Add the the secret `PROXY_SECRET` with a random string
|
||||
3. Clone this repo
|
||||
|
24
apps/node/.dockerignore
Normal file
24
apps/node/.dockerignore
Normal file
@ -0,0 +1,24 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
@ -1,4 +1,4 @@
|
||||
NODE_ID=1
|
||||
|
||||
API_PORT=3000
|
||||
API_PORT=3001
|
||||
INFISICAL_TOKEN=YOUR_TOKEN
|
42
apps/node/Dockerfile
Normal file
42
apps/node/Dockerfile
Normal file
@ -0,0 +1,42 @@
|
||||
FROM fascinated/docker-images:node-pnpm-latest AS base
|
||||
|
||||
# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
|
||||
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.
|
||||
|
||||
FROM base AS builder
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
RUN pnpm install -g turbo
|
||||
COPY . .
|
||||
RUN turbo prune node --docker
|
||||
|
||||
# Add lockfile and package.json's of isolated subworkspace
|
||||
FROM base AS installer
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
WORKDIR /app
|
||||
|
||||
# First install dependencies (as they change less often)
|
||||
COPY --from=builder /app/out/json/ .
|
||||
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN pnpm install
|
||||
|
||||
# Build the project and its dependencies
|
||||
COPY --from=builder /app/out/full/ .
|
||||
COPY turbo.json turbo.json
|
||||
|
||||
RUN pnpm run build --filter=node...
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 expressjs
|
||||
RUN adduser --system --uid 1001 expressjs
|
||||
USER expressjs
|
||||
COPY --from=installer /app .
|
||||
|
||||
CMD node apps/node/dist/index.js
|
241
apps/node/package-lock.json
generated
241
apps/node/package-lock.json
generated
@ -1,241 +0,0 @@
|
||||
{
|
||||
"name": "node",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "node",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
},
|
||||
"../../node_modules/.pnpm/typescript@5.2.2/node_modules/typescript": {
|
||||
"version": "5.2.2",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@esfx/canceltoken": "^1.0.0",
|
||||
"@octokit/rest": "^19.0.13",
|
||||
"@types/chai": "^4.3.4",
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/glob": "^8.1.0",
|
||||
"@types/microsoft__typescript-etw": "^0.1.1",
|
||||
"@types/minimist": "^1.2.2",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/ms": "^0.7.31",
|
||||
"@types/node": "latest",
|
||||
"@types/source-map-support": "^0.5.6",
|
||||
"@types/which": "^2.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"@typescript-eslint/utils": "^6.0.0",
|
||||
"azure-devops-node-api": "^12.0.0",
|
||||
"c8": "^7.14.0",
|
||||
"chai": "^4.3.7",
|
||||
"chalk": "^4.1.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"del": "^6.1.1",
|
||||
"diff": "^5.1.0",
|
||||
"esbuild": "^0.18.1",
|
||||
"eslint": "^8.22.0",
|
||||
"eslint-formatter-autolinkable-stylish": "^1.2.0",
|
||||
"eslint-plugin-local": "^1.0.0",
|
||||
"eslint-plugin-no-null": "^1.0.2",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"fast-xml-parser": "^4.0.11",
|
||||
"fs-extra": "^9.1.0",
|
||||
"glob": "^8.1.0",
|
||||
"hereby": "^1.6.4",
|
||||
"jsonc-parser": "^3.2.0",
|
||||
"minimist": "^1.2.8",
|
||||
"mocha": "^10.2.0",
|
||||
"mocha-fivemat-progress-reporter": "^0.1.0",
|
||||
"ms": "^2.1.3",
|
||||
"node-fetch": "^3.2.10",
|
||||
"source-map-support": "^0.5.21",
|
||||
"tslib": "^2.5.0",
|
||||
"typescript": "^5.0.2",
|
||||
"which": "^2.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/@cspotcode/source-map-support": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||
"integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
|
||||
"dependencies": {
|
||||
"@jridgewell/trace-mapping": "0.3.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/resolve-uri": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
|
||||
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/sourcemap-codec": {
|
||||
"version": "1.4.15",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
|
||||
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg=="
|
||||
},
|
||||
"node_modules/@jridgewell/trace-mapping": {
|
||||
"version": "0.3.9",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
|
||||
"integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.0.3",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tsconfig/node10": {
|
||||
"version": "1.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
|
||||
"integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA=="
|
||||
},
|
||||
"node_modules/@tsconfig/node12": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
|
||||
"integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag=="
|
||||
},
|
||||
"node_modules/@tsconfig/node14": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
|
||||
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow=="
|
||||
},
|
||||
"node_modules/@tsconfig/node16": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz",
|
||||
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA=="
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.0.tgz",
|
||||
"integrity": "sha512-nekiGu2NDb1BcVofVcEKMIwzlx4NjHlcjhoxxKBNLtz15Y1z7MYf549DFvkHSId02Ax6kGwWntIBPC3l/JZcmw==",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.11.2",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz",
|
||||
"integrity": "sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==",
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn-walk": {
|
||||
"version": "8.3.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.0.tgz",
|
||||
"integrity": "sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/arg": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA=="
|
||||
},
|
||||
"node_modules/create-require": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ=="
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||
"engines": {
|
||||
"node": ">=0.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw=="
|
||||
},
|
||||
"node_modules/ts-node": {
|
||||
"version": "10.9.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
|
||||
"integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
|
||||
"dependencies": {
|
||||
"@cspotcode/source-map-support": "^0.8.0",
|
||||
"@tsconfig/node10": "^1.0.7",
|
||||
"@tsconfig/node12": "^1.0.7",
|
||||
"@tsconfig/node14": "^1.0.0",
|
||||
"@tsconfig/node16": "^1.0.2",
|
||||
"acorn": "^8.4.1",
|
||||
"acorn-walk": "^8.1.1",
|
||||
"arg": "^4.1.0",
|
||||
"create-require": "^1.1.0",
|
||||
"diff": "^4.0.1",
|
||||
"make-error": "^1.1.1",
|
||||
"v8-compile-cache-lib": "^3.0.1",
|
||||
"yn": "3.1.1"
|
||||
},
|
||||
"bin": {
|
||||
"ts-node": "dist/bin.js",
|
||||
"ts-node-cwd": "dist/bin-cwd.js",
|
||||
"ts-node-esm": "dist/bin-esm.js",
|
||||
"ts-node-script": "dist/bin-script.js",
|
||||
"ts-node-transpile-only": "dist/bin-transpile.js",
|
||||
"ts-script": "dist/bin-script-deprecated.js"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@swc/core": ">=1.2.50",
|
||||
"@swc/wasm": ">=1.2.50",
|
||||
"@types/node": "*",
|
||||
"typescript": ">=2.7"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@swc/core": {
|
||||
"optional": true
|
||||
},
|
||||
"@swc/wasm": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"resolved": "../../node_modules/.pnpm/typescript@5.2.2/node_modules/typescript",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "5.26.5",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/v8-compile-cache-lib": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
||||
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg=="
|
||||
},
|
||||
"node_modules/yn": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,15 +6,17 @@
|
||||
"author": "fascinated",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "tsup src/index.ts --format cjs,esm --dts",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "nodemon --exec ts-node src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.6.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"server": "workspace:*",
|
||||
"utils": "workspace:*",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
"typescript": "^5.2.2",
|
||||
"utils": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ export default class ProxyRoute extends Route {
|
||||
}
|
||||
|
||||
async handle(req: Request, res: Response) {
|
||||
const before = Date.now();
|
||||
const json = req.body;
|
||||
const secret = json.secret;
|
||||
if (!secret) {
|
||||
@ -25,12 +26,8 @@ export default class ProxyRoute extends Route {
|
||||
res.status(400).json(RouteMessages.badRequest("No URL provided"));
|
||||
return;
|
||||
}
|
||||
// TODO: handle rate limiting? and/or caching?
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
try {
|
||||
const response = await axios.get(url);
|
||||
const data = response.data;
|
||||
const headers = response.headers;
|
||||
|
||||
@ -40,6 +37,10 @@ export default class ProxyRoute extends Route {
|
||||
delete headers["access-control-allow-credentials"];
|
||||
delete headers["access-control-allow-headers"];
|
||||
delete headers["access-control-allow-methods"];
|
||||
delete headers["access-control-expose-headers"];
|
||||
delete headers["cross-origin-embedder-policy"];
|
||||
delete headers["cross-origin-opener-policy"];
|
||||
delete headers["cross-origin-resource-policy"];
|
||||
|
||||
// Cloudflare headers
|
||||
delete headers["server"];
|
||||
@ -49,7 +50,26 @@ export default class ProxyRoute extends Route {
|
||||
delete headers["cf-ray"];
|
||||
delete headers["alt-svc"];
|
||||
|
||||
// Misc headers
|
||||
delete headers["transfer-encoding"];
|
||||
delete headers["content-security-policy"];
|
||||
delete headers["strict-transport-security"];
|
||||
delete headers["referrer-policy"];
|
||||
|
||||
// Add node specific headers
|
||||
headers["x-proxy-node"] = process.env.NODE_ID;
|
||||
headers["x-proxy-response-time"] = Date.now() - before + "ms";
|
||||
|
||||
// Add CORS headers
|
||||
headers["access-control-allow-origin"] = "*";
|
||||
headers["access-control-allow-methods"] = "*";
|
||||
|
||||
// Return the JSON response
|
||||
res.status(response.status).set(headers).json(data);
|
||||
res.status(response.status).set(headers).send(data);
|
||||
} catch (ex) {
|
||||
res
|
||||
.status(500)
|
||||
.json(RouteMessages.internalServerError("Error fetching URL"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { GetOptions } from "infisical-node/lib/types/InfisicalClient";
|
||||
import { createInfisicalClient } from "utils";
|
||||
|
||||
export let PROXY_SECRET: string;
|
||||
@ -9,7 +10,13 @@ export async function initSecrets(token: string) {
|
||||
console.log("Initializing secrets...");
|
||||
|
||||
const infisicalClient = createInfisicalClient(token);
|
||||
const proxySecret = (await infisicalClient.getSecret("PROXY_SECRET"))
|
||||
const options: GetOptions = {
|
||||
environment: process.env.NODE_ENV === "production" ? "main" : "dev",
|
||||
path: "/",
|
||||
type: "shared",
|
||||
};
|
||||
|
||||
const proxySecret = (await infisicalClient.getSecret("PROXY_SECRET", options))
|
||||
.secretValue;
|
||||
|
||||
if (!proxySecret) {
|
||||
|
@ -1,7 +1,3 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
}
|
||||
"extends": "tsconfig/server.json"
|
||||
}
|
||||
|
24
apps/proxy/.dockerignore
Normal file
24
apps/proxy/.dockerignore
Normal file
@ -0,0 +1,24 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
2
apps/proxy/.env-example
Normal file
2
apps/proxy/.env-example
Normal file
@ -0,0 +1,2 @@
|
||||
API_PORT=3000
|
||||
INFISICAL_TOKEN=YOUR_TOKEN
|
39
apps/proxy/Dockerfile
Normal file
39
apps/proxy/Dockerfile
Normal file
@ -0,0 +1,39 @@
|
||||
FROM fascinated/docker-images:node-pnpm-latest AS base
|
||||
|
||||
# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
|
||||
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.
|
||||
|
||||
FROM base AS builder
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
RUN pnpm install -g turbo
|
||||
COPY . .
|
||||
RUN turbo prune proxy --docker
|
||||
|
||||
# Add lockfile and package.json's of isolated subworkspace
|
||||
FROM base AS installer
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
WORKDIR /app
|
||||
|
||||
# First install dependencies (as they change less often)
|
||||
COPY --from=builder /app/out/json/ .
|
||||
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN pnpm install
|
||||
|
||||
# Build the project and its dependencies
|
||||
COPY --from=builder /app/out/full/ .
|
||||
COPY turbo.json turbo.json
|
||||
|
||||
RUN pnpm run build --filter=proxy...
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 expressjs
|
||||
RUN adduser --system --uid 1001 expressjs
|
||||
USER expressjs
|
||||
COPY --from=installer /app .
|
||||
|
||||
CMD node apps/proxy/dist/index.js
|
25
apps/proxy/package.json
Normal file
25
apps/proxy/package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "proxy",
|
||||
"version": "1.0.0",
|
||||
"description": "The proxy server for the project",
|
||||
"main": "dist/index.js",
|
||||
"author": "fascinated",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts --format cjs,esm --dts",
|
||||
"start": "node dist/index.js",
|
||||
"dev": "nodemon --exec ts-node src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.6.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"server": "workspace:*",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2",
|
||||
"utils": "workspace:*",
|
||||
"node-cache": "^5.1.2",
|
||||
"@influxdata/influxdb-client": "^1.33.2",
|
||||
"mongoose": "^8.0.0"
|
||||
}
|
||||
}
|
11
apps/proxy/src/db/metrics.ts
Normal file
11
apps/proxy/src/db/metrics.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import mongoose, { Model } from "mongoose";
|
||||
const { Schema } = mongoose;
|
||||
|
||||
const metricsSchema = new Schema({
|
||||
_id: String,
|
||||
totalRequests: Number,
|
||||
});
|
||||
|
||||
export const MetricsSchema =
|
||||
(mongoose.models.Metrics as Model<typeof metricsSchema>) ||
|
||||
mongoose.model("Metrics", metricsSchema);
|
18
apps/proxy/src/db/mongo.ts
Normal file
18
apps/proxy/src/db/mongo.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
/**
|
||||
* Creates a connection to Mongo
|
||||
*
|
||||
* @param uri the URI of the mongo instance
|
||||
* @returns the mongoose connection
|
||||
*/
|
||||
export async function connectMongo(uri: string) {
|
||||
// Check if mongoose is already connected
|
||||
if (mongoose.connection.readyState) {
|
||||
return;
|
||||
}
|
||||
return mongoose.connect(uri, {
|
||||
autoCreate: true,
|
||||
family: 4,
|
||||
});
|
||||
}
|
69
apps/proxy/src/index.ts
Normal file
69
apps/proxy/src/index.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { QueryApi, WriteApi } from "@influxdata/influxdb-client";
|
||||
import dotenv from "dotenv";
|
||||
import { RouteManager, RouteMessages, createServer } from "server";
|
||||
import { checkEnvironmentVariables, createInfluxClient } from "utils";
|
||||
import { connectMongo } from "./db/mongo";
|
||||
import NodeManager from "./node/nodeManager";
|
||||
import ProxyRoute from "./routes/proxy";
|
||||
import {
|
||||
INFLUXDB_BUCKET,
|
||||
INFLUXDB_ORG,
|
||||
INFLUXDB_TOKEN,
|
||||
INFLUXDB_URL,
|
||||
MONGO_URI,
|
||||
initSecrets,
|
||||
} from "./secrets";
|
||||
|
||||
dotenv.config(); // load .env file
|
||||
|
||||
// Check environment variables
|
||||
const envVarsValid = checkEnvironmentVariables("API_PORT", "INFISICAL_TOKEN");
|
||||
if (!envVarsValid) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export let InfluxWriteApi: WriteApi;
|
||||
export let InfluxQueryApi: QueryApi;
|
||||
|
||||
/**
|
||||
* The node manager for all of the loaded nodes
|
||||
*/
|
||||
export const nodeManager = new NodeManager();
|
||||
|
||||
(async () => {
|
||||
await initSecrets(process.env.INFISICAL_TOKEN!); // Load the infisical secrets
|
||||
|
||||
// Init MongoDB
|
||||
await connectMongo(MONGO_URI);
|
||||
|
||||
const routeManager = new RouteManager();
|
||||
routeManager.addRoute(new ProxyRoute());
|
||||
|
||||
// Init InfluxDB
|
||||
const influxClient = createInfluxClient(
|
||||
INFLUXDB_TOKEN,
|
||||
INFLUXDB_URL,
|
||||
INFLUXDB_ORG,
|
||||
INFLUXDB_BUCKET
|
||||
);
|
||||
if (!influxClient) {
|
||||
console.log("Influx client failed to initialize, exiting...");
|
||||
process.exit(1);
|
||||
}
|
||||
InfluxWriteApi = influxClient.influxWriteClient;
|
||||
InfluxQueryApi = influxClient.influxQueryClient;
|
||||
|
||||
const server = createServer({
|
||||
port: process.env.API_PORT || 3000,
|
||||
});
|
||||
|
||||
server.all("*", (req, res) => {
|
||||
// Handle all paths to the proxy route
|
||||
const routes = routeManager.getRoutes();
|
||||
if (!routes || routes.length === 0 || !routes[0]) {
|
||||
res.status(500).json(RouteMessages.internalServerError("No routes"));
|
||||
return;
|
||||
}
|
||||
routes[0].handle(req, res);
|
||||
});
|
||||
})();
|
48
apps/proxy/src/node/node.ts
Normal file
48
apps/proxy/src/node/node.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import axios from "axios";
|
||||
import { PROXY_SECRET } from "../secrets";
|
||||
|
||||
type NodeOptions = {
|
||||
/**
|
||||
* The URL to node
|
||||
*/
|
||||
url: string;
|
||||
};
|
||||
|
||||
export default class Node {
|
||||
/**
|
||||
* The URL to node
|
||||
*/
|
||||
private url: string;
|
||||
|
||||
constructor({ url }: NodeOptions) {
|
||||
this.url = url;
|
||||
|
||||
// todo: ping node and check status
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to node
|
||||
*
|
||||
* @returns the URL
|
||||
*/
|
||||
getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a URL from the node.
|
||||
* The node will fetch the URL and return the response.
|
||||
*
|
||||
* @param url the URL to fetch
|
||||
*/
|
||||
async fetch(url: string) {
|
||||
const response = await axios.get(this.getUrl() + "/proxy", {
|
||||
data: {
|
||||
url: url,
|
||||
secret: PROXY_SECRET,
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
28
apps/proxy/src/node/nodeManager.ts
Normal file
28
apps/proxy/src/node/nodeManager.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import Node from "./node";
|
||||
|
||||
export default class NodeManager {
|
||||
/**
|
||||
* The nodes
|
||||
*/
|
||||
private nodes: Node[];
|
||||
|
||||
constructor() {
|
||||
const nodes = process.env.NODES;
|
||||
if (!nodes) {
|
||||
throw new Error("No nodes found in environment variable");
|
||||
}
|
||||
|
||||
const nodeUrls = nodes.split(",");
|
||||
this.nodes = nodeUrls.map((url) => new Node({ url }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random node
|
||||
*
|
||||
* @returns the node
|
||||
*/
|
||||
getRandomNode() {
|
||||
const index = Math.floor(Math.random() * this.nodes.length);
|
||||
return this.nodes[index];
|
||||
}
|
||||
}
|
177
apps/proxy/src/routes/proxy.ts
Normal file
177
apps/proxy/src/routes/proxy.ts
Normal file
@ -0,0 +1,177 @@
|
||||
import { Point } from "@influxdata/influxdb-client";
|
||||
import { Request, Response } from "express";
|
||||
import Cache from "node-cache";
|
||||
import { Route, RouteMessages } from "server";
|
||||
import { InfluxWriteApi, nodeManager } from "..";
|
||||
import { MetricsSchema } from "../db/metrics";
|
||||
|
||||
const IGNORED_PATHS = ["/favicon.ico"];
|
||||
|
||||
/**
|
||||
* The total requests that have been made
|
||||
* TODO: move this to a metrics file
|
||||
*/
|
||||
let totalRequests: number | undefined = undefined;
|
||||
|
||||
const cache = new Cache({
|
||||
stdTTL: 300, // 5 minutes
|
||||
});
|
||||
type CachedRequest = {
|
||||
nodeId: string;
|
||||
status: number;
|
||||
headers: any;
|
||||
data: any;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a request
|
||||
*
|
||||
* @param nodeId the node ID that handled the request
|
||||
* @param url the URL of the request
|
||||
* @param status the status code of the request
|
||||
* @param time the time it took to handle the request (or true if it was cached)
|
||||
*/
|
||||
function log(
|
||||
nodeId: string,
|
||||
url: string,
|
||||
status: number,
|
||||
time: number | boolean
|
||||
) {
|
||||
console.log(
|
||||
`[node: ${nodeId}] ${url} - ${status} (${
|
||||
time === true ? "cached" : time + "ms"
|
||||
})`
|
||||
);
|
||||
}
|
||||
|
||||
type InfluxLog = {
|
||||
nodeId: string;
|
||||
url: string;
|
||||
status: number;
|
||||
time?: number;
|
||||
cached?: boolean;
|
||||
};
|
||||
/**
|
||||
* Creates an InfluxDB point and writes it to the database
|
||||
*
|
||||
* @param nodeId the node ID that handled the request
|
||||
* @param url the URL of the request
|
||||
* @param status the status code of the request
|
||||
* @param time the time it took to handle the request (or true if it was cached)
|
||||
*/
|
||||
async function logRequestToDatabase({
|
||||
nodeId,
|
||||
url,
|
||||
status,
|
||||
time,
|
||||
cached,
|
||||
}: InfluxLog) {
|
||||
if (totalRequests === undefined) {
|
||||
const metrics: any = await MetricsSchema.findOne({ _id: "proxy" }).exec();
|
||||
if (metrics) {
|
||||
totalRequests = metrics.totalRequests as number;
|
||||
} else {
|
||||
totalRequests = 0;
|
||||
}
|
||||
}
|
||||
totalRequests++;
|
||||
MetricsSchema.updateOne(
|
||||
{ _id: "proxy" },
|
||||
{ $set: { totalRequests: totalRequests } },
|
||||
{ upsert: true }
|
||||
).exec();
|
||||
|
||||
const point = new Point("proxy")
|
||||
.tag("type", "request")
|
||||
.tag("node", nodeId)
|
||||
.booleanField("cached", cached ? true : false)
|
||||
.stringField("url", url)
|
||||
.intField("status", status)
|
||||
.timestamp(Date.now());
|
||||
if (time) {
|
||||
point.intField("time", time);
|
||||
}
|
||||
try {
|
||||
InfluxWriteApi.writePoint(point);
|
||||
InfluxWriteApi.writePoint(
|
||||
new Point("proxy")
|
||||
.intField("totalRequests", totalRequests)
|
||||
.timestamp(Date.now())
|
||||
);
|
||||
} catch (ex) {
|
||||
console.log("Failed to write to influx");
|
||||
console.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
export default class ProxyRoute extends Route {
|
||||
constructor() {
|
||||
super({ path: "/" });
|
||||
}
|
||||
|
||||
async handle(req: Request, res: Response) {
|
||||
const url = req.url.substring(1);
|
||||
if (!url) {
|
||||
res.status(400).json(RouteMessages.badRequest("No URL provided"));
|
||||
return;
|
||||
}
|
||||
if (IGNORED_PATHS.includes(url)) {
|
||||
res.status(404).send("Not found");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const cachedRequest = cache.get<CachedRequest>(url);
|
||||
if (cachedRequest) {
|
||||
const { status, headers, data, nodeId } = cachedRequest;
|
||||
|
||||
res.status(status).set(headers).json(data);
|
||||
log(nodeId, url, status, true);
|
||||
return logRequestToDatabase({
|
||||
nodeId: nodeId,
|
||||
url,
|
||||
status: status,
|
||||
cached: true,
|
||||
});
|
||||
}
|
||||
|
||||
const node = nodeManager.getRandomNode();
|
||||
if (!node) {
|
||||
res
|
||||
.status(500)
|
||||
.json(RouteMessages.internalServerError("No nodes available"));
|
||||
return;
|
||||
}
|
||||
|
||||
const before = Date.now();
|
||||
const response = await node.fetch(url);
|
||||
const nodeId = response.headers["x-proxy-node"];
|
||||
const { status, headers, data } = response;
|
||||
|
||||
if (response.status === 500) {
|
||||
res.status(500).json(RouteMessages.internalServerError(data));
|
||||
return;
|
||||
}
|
||||
|
||||
log(nodeId, url, status, Date.now() - before);
|
||||
logRequestToDatabase({
|
||||
nodeId,
|
||||
url,
|
||||
status: status,
|
||||
time: Date.now() - before,
|
||||
cached: false,
|
||||
});
|
||||
cache.set(url, {
|
||||
nodeId: nodeId,
|
||||
status: status,
|
||||
headers: headers,
|
||||
data: data,
|
||||
} as CachedRequest);
|
||||
|
||||
// Send the response to the client
|
||||
res.status(status).set(headers).send(data);
|
||||
} catch (ex: any) {
|
||||
res.status(500).json(RouteMessages.internalServerError(ex.message || ex));
|
||||
}
|
||||
}
|
||||
}
|
80
apps/proxy/src/secrets.ts
Normal file
80
apps/proxy/src/secrets.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import { GetOptions } from "infisical-node/lib/types/InfisicalClient";
|
||||
import { createInfisicalClient } from "utils";
|
||||
|
||||
export let PROXY_SECRET: string;
|
||||
|
||||
// InfluxDB
|
||||
export let INFLUXDB_URL: string;
|
||||
export let INFLUXDB_ORG: string;
|
||||
export let INFLUXDB_BUCKET: string;
|
||||
export let INFLUXDB_TOKEN: string;
|
||||
|
||||
// MongoDB
|
||||
export let MONGO_URI: string;
|
||||
|
||||
/**
|
||||
* Initialize the secrets from Infisical
|
||||
*/
|
||||
export async function initSecrets(token: string) {
|
||||
console.log("Initializing secrets...");
|
||||
|
||||
const infisicalClient = createInfisicalClient(token);
|
||||
const options: GetOptions = {
|
||||
environment: process.env.NODE_ENV === "production" ? "main" : "dev",
|
||||
path: "/",
|
||||
type: "shared",
|
||||
};
|
||||
|
||||
const proxySecret = (await infisicalClient.getSecret("PROXY_SECRET", options))
|
||||
.secretValue;
|
||||
|
||||
// InfluxDB
|
||||
const influxDBUrl = (await infisicalClient.getSecret("INFLUXDB_URL", options))
|
||||
.secretValue;
|
||||
const influxDBOrg = (await infisicalClient.getSecret("INFLUXDB_ORG", options))
|
||||
.secretValue;
|
||||
const influxDBBucket = (
|
||||
await infisicalClient.getSecret("INFLUXDB_BUCKET", options)
|
||||
).secretValue;
|
||||
const influxDBToken = (
|
||||
await infisicalClient.getSecret("INFLUXDB_TOKEN", options)
|
||||
).secretValue;
|
||||
|
||||
// Mongo
|
||||
const mongoUri = (await infisicalClient.getSecret("MONGO_URI", options))
|
||||
.secretValue;
|
||||
|
||||
if (!proxySecret) {
|
||||
throw new Error("PROXY_SECRET not set in Infisical");
|
||||
}
|
||||
|
||||
// InfluxDB
|
||||
if (!influxDBUrl) {
|
||||
throw new Error("INFLUXDB_URL not set in Infisical");
|
||||
}
|
||||
if (!influxDBOrg) {
|
||||
throw new Error("INFLUXDB_ORG not set in Infisical");
|
||||
}
|
||||
if (!influxDBBucket) {
|
||||
throw new Error("INFLUXDB_BUCKET not set in Infisical");
|
||||
}
|
||||
if (!influxDBToken) {
|
||||
throw new Error("INFLUXDB_TOKEN not set in Infisical");
|
||||
}
|
||||
|
||||
// Mongo
|
||||
if (!mongoUri) {
|
||||
throw new Error("MONGO_URI not set in Infisical");
|
||||
}
|
||||
|
||||
PROXY_SECRET = proxySecret;
|
||||
|
||||
// InfluxDB
|
||||
INFLUXDB_URL = influxDBUrl;
|
||||
INFLUXDB_ORG = influxDBOrg;
|
||||
INFLUXDB_BUCKET = influxDBBucket;
|
||||
INFLUXDB_TOKEN = influxDBToken;
|
||||
|
||||
// Mongo
|
||||
MONGO_URI = mongoUri;
|
||||
}
|
6
apps/proxy/tsconfig.json
Normal file
6
apps/proxy/tsconfig.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
38
docker-compose.yml
Normal file
38
docker-compose.yml
Normal file
@ -0,0 +1,38 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
proxy:
|
||||
image: fascinated/proxy:proxy-latest
|
||||
container_name: Proxy
|
||||
restart: always
|
||||
ports:
|
||||
- 3000:3000
|
||||
environment:
|
||||
API_PORT: 3000
|
||||
INFISICAL_TOKEN: ${INFISICAL_TOKEN}
|
||||
|
||||
# Add your nodes here (eg: http://localhost:3001,http://localhost:3002, etc.)
|
||||
NODES: http://node-1:3000,http://node-2:3000
|
||||
|
||||
node-1:
|
||||
image: fascinated/proxy:node-latest
|
||||
container_name: Node_1
|
||||
restart: always
|
||||
# Uncomment the ports if you want to access the node directly
|
||||
#ports:
|
||||
# - 3000:3000
|
||||
environment:
|
||||
API_PORT: 3000
|
||||
INFISICAL_TOKEN: ${INFISICAL_TOKEN}
|
||||
NODE_ID: 1
|
||||
|
||||
node-2:
|
||||
image: fascinated/proxy:node-latest
|
||||
container_name: Node_2
|
||||
restart: always
|
||||
# Uncomment the ports if you want to access the node directly
|
||||
#ports:
|
||||
# - 3000:3000
|
||||
environment:
|
||||
API_PORT: 3000
|
||||
INFISICAL_TOKEN: ${INFISICAL_TOKEN}
|
||||
NODE_ID: 1
|
11
package.json
11
package.json
@ -1,5 +1,7 @@
|
||||
{
|
||||
"name": "proxy",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@8.10.5",
|
||||
"scripts": {
|
||||
"build": "turbo run build",
|
||||
"dev": "turbo run dev",
|
||||
@ -7,18 +9,19 @@
|
||||
"format": "prettier --write \"**/*.{ts,tsx,md}\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@influxdata/influxdb-client": "^1.33.2",
|
||||
"dotenv": "^16.3.1",
|
||||
"eslint": "^8.48.0",
|
||||
"express": "^4.18.2",
|
||||
"infisical-node": "^1.5.0",
|
||||
"node-cache": "^5.1.2",
|
||||
"nodemon": "^3.0.1",
|
||||
"prettier": "^3.0.3",
|
||||
"tsconfig": "workspace:*",
|
||||
"tsup": "^8.0.0",
|
||||
"turbo": "latest"
|
||||
},
|
||||
"packageManager": "pnpm@8.9.0",
|
||||
"name": "proxy",
|
||||
"dependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"infisical-node": "^1.5.0"
|
||||
"mongoose": "8.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,14 @@
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts --format cjs,esm --dts",
|
||||
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { badRequest } from "./messages/badRequest";
|
||||
import { internalServerError } from "./messages/internalServerError";
|
||||
import { unknownRoute } from "./messages/unknownRoute";
|
||||
|
||||
export const RouteMessages = {
|
||||
unknownRoute: unknownRoute,
|
||||
badRequest: badRequest,
|
||||
internalServerError: internalServerError,
|
||||
};
|
||||
|
||||
export * from "./route/route";
|
||||
|
10
packages/server/src/messages/internalServerError.ts
Normal file
10
packages/server/src/messages/internalServerError.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { baseMessage } from "./baseMessage";
|
||||
|
||||
/**
|
||||
* Creates a response for an internal server error
|
||||
*
|
||||
* @returns the internal server error message
|
||||
*/
|
||||
export function internalServerError(message: string) {
|
||||
return baseMessage(true, message);
|
||||
}
|
@ -19,7 +19,7 @@ export class RouteManager {
|
||||
* @returns the route or undefined if not found
|
||||
*/
|
||||
getRoute(path: string) {
|
||||
return this.routes.find((route) => route.getPath() === path);
|
||||
return this.routes.find((route) => path.startsWith(route.getPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,4 @@
|
||||
import express from "express";
|
||||
import express, { Express } from "express";
|
||||
|
||||
type ServerType = {
|
||||
/**
|
||||
@ -10,7 +10,7 @@ type ServerType = {
|
||||
onLoaded?: () => void;
|
||||
};
|
||||
|
||||
export function createServer({ port = 3000, onLoaded }: ServerType) {
|
||||
export function createServer({ port = 3000, onLoaded }: ServerType): Express {
|
||||
if (typeof port === "string") {
|
||||
port = Number(port);
|
||||
if (isNaN(port)) {
|
||||
@ -25,8 +25,8 @@ export function createServer({ port = 3000, onLoaded }: ServerType) {
|
||||
// Remove the X-Powered-By header
|
||||
server.disable("x-powered-by");
|
||||
|
||||
// Turn on ETag support (for caching)
|
||||
server.enable("etag");
|
||||
// Remove the ETag header (so that the client doesn't cache the response)
|
||||
server.disable("etag");
|
||||
|
||||
// Listen on the specified port
|
||||
server.listen(port, () => {
|
||||
|
@ -1,7 +1,3 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
}
|
||||
"extends": "tsconfig/server.json"
|
||||
}
|
||||
|
@ -14,5 +14,5 @@
|
||||
"noEmit": true,
|
||||
"lib": ["es2022", "dom", "dom.iterable"]
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
@ -6,6 +6,11 @@
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts --format cjs,esm --dts",
|
||||
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from "./envVariables";
|
||||
export * from "./secrets";
|
||||
export * from "./influx/influx";
|
||||
export * from "./secrets/secrets";
|
||||
|
29
packages/utils/src/influx/influx.ts
Normal file
29
packages/utils/src/influx/influx.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { InfluxDB } from "@influxdata/influxdb-client";
|
||||
|
||||
/**
|
||||
* Creates an InfluxDB client
|
||||
*
|
||||
* @param token the influx token
|
||||
* @param url the url of the influx instance
|
||||
* @param org the org of the influx instance
|
||||
* @param bucket the bucket of the influx instance
|
||||
* @returns
|
||||
*/
|
||||
function createInfluxClient(
|
||||
token: string,
|
||||
url: string,
|
||||
org: string,
|
||||
bucket: string
|
||||
) {
|
||||
const client = new InfluxDB({
|
||||
url: url,
|
||||
token: token,
|
||||
});
|
||||
|
||||
return {
|
||||
influxWriteClient: client.getWriteApi(org, bucket, "ms"),
|
||||
influxQueryClient: client.getQueryApi(org),
|
||||
};
|
||||
}
|
||||
|
||||
export { createInfluxClient };
|
@ -1,7 +1,3 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
}
|
||||
"extends": "tsconfig/server.json"
|
||||
}
|
||||
|
1135
pnpm-lock.yaml
generated
1135
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
6
renovate.json
Normal file
6
renovate.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"local>Fascinated/renovate-config"
|
||||
]
|
||||
}
|
@ -3,8 +3,8 @@
|
||||
"globalDependencies": ["**/.env"],
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"dependsOn": ["^build"],
|
||||
"outputs": [".next/**", "!.next/cache/**"]
|
||||
"outputs": ["dist/**"],
|
||||
"dependsOn": ["^build"]
|
||||
},
|
||||
"lint": {},
|
||||
"dev": {
|
||||
|
Reference in New Issue
Block a user