inital commit

This commit is contained in:
Lee 2023-11-14 17:56:44 +00:00
commit 161486bf49
38 changed files with 5094 additions and 0 deletions

36
.gitignore vendored Normal file

@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
.pnp
.pnp.js
# testing
coverage
# next.js
.next/
out/
build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# turbo
.turbo
# vercel
.vercel

1
.npmrc Normal file

@ -0,0 +1 @@
auto-install-peers = true

7
.vscode/settings.json vendored Normal file

@ -0,0 +1,7 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
}
]
}

81
README.md Normal file

@ -0,0 +1,81 @@
# Turborepo starter
This is an official starter Turborepo.
## Using this example
Run the following command:
```sh
npx create-turbo@latest
```
## What's inside?
This Turborepo includes the following packages/apps:
### Apps and Packages
- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `ui`: a stub React component library shared by both `web` and `docs` applications
- `eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `tsconfig`: `tsconfig.json`s used throughout the monorepo
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).
### Utilities
This Turborepo has some additional tools already setup for you:
- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting
### Build
To build all apps and packages, run the following command:
```
cd my-turborepo
pnpm build
```
### Develop
To develop all apps and packages, run the following command:
```
cd my-turborepo
pnpm dev
```
### Remote Caching
Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:
```
cd my-turborepo
npx turbo login
```
This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
```
npx turbo link
```
## Useful Links
Learn more about the power of Turborepo:
- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)

4
apps/node/.env-example Normal file

@ -0,0 +1,4 @@
NODE_ID=1
API_PORT=3000
INFISICAL_TOKEN=YOUR_TOKEN

241
apps/node/package-lock.json generated Normal file

@ -0,0 +1,241 @@
{
"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"
}
}
}
}

20
apps/node/package.json Normal file

@ -0,0 +1,20 @@
{
"name": "node",
"version": "1.0.0",
"description": "A node for the proxy",
"main": "dist/index.js",
"author": "fascinated",
"license": "MIT",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "nodemon --exec ts-node src/index.ts"
},
"dependencies": {
"axios": "^1.6.1",
"server": "workspace:*",
"utils": "workspace:*",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}

34
apps/node/src/index.ts Normal file

@ -0,0 +1,34 @@
import dotenv from "dotenv";
import { RouteManager, RouteMessages, createServer } from "server";
import { checkEnvironmentVariables } from "utils";
import ProxyRoute from "./routes/proxy";
import { initSecrets } from "./secrets";
dotenv.config(); // load .env file
// Check environment variables
const envVarsValid = checkEnvironmentVariables("API_PORT", "INFISICAL_TOKEN");
if (!envVarsValid) {
process.exit(1);
}
const server = createServer({
port: process.env.API_PORT || 3000,
onLoaded: async () => {
await initSecrets(process.env.INFISICAL_TOKEN!); // Load the infisical secrets
const routeManager = new RouteManager();
routeManager.addRoute(new ProxyRoute());
server.all("*", (req, res) => {
const route = routeManager.getRoute(req.path);
if (route) {
route.handle(req, res);
return;
}
// Handle unknown routes
res.json(RouteMessages.unknownRoute());
});
},
});

@ -0,0 +1,55 @@
import axios from "axios";
import { Request, Response } from "express";
import { Route, RouteMessages } from "server";
import { PROXY_SECRET } from "../secrets";
export default class ProxyRoute extends Route {
constructor() {
super({ path: "/proxy" });
}
async handle(req: Request, res: Response) {
const json = req.body;
const secret = json.secret;
if (!secret) {
res.status(401).json(RouteMessages.badRequest("No secret provided"));
return;
}
if (secret !== PROXY_SECRET) {
res.status(401).json(RouteMessages.badRequest("Invalid secret"));
return;
}
const url = json.url;
if (!url) {
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",
},
});
const data = response.data;
const headers = response.headers;
// Is delete the best way to do this??
// Remove CORS headers
delete headers["access-control-allow-origin"];
delete headers["access-control-allow-credentials"];
delete headers["access-control-allow-headers"];
delete headers["access-control-allow-methods"];
// Cloudflare headers
delete headers["server"];
delete headers["nel"];
delete headers["report-to"];
delete headers["cf-cache-status"];
delete headers["cf-ray"];
delete headers["alt-svc"];
// Return the JSON response
res.status(response.status).set(headers).json(data);
}
}

20
apps/node/src/secrets.ts Normal file

@ -0,0 +1,20 @@
import { createInfisicalClient } from "utils";
export let PROXY_SECRET: string;
/**
* Initialize the secrets from Infisical
*/
export async function initSecrets(token: string) {
console.log("Initializing secrets...");
const infisicalClient = createInfisicalClient(token);
const proxySecret = (await infisicalClient.getSecret("PROXY_SECRET"))
.secretValue;
if (!proxySecret) {
throw new Error("PROXY_SECRET not set in Infisical");
}
PROXY_SECRET = proxySecret;
}

7
apps/node/tsconfig.json Normal file

@ -0,0 +1,7 @@
{
"extends": "tsconfig/server.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}

24
package.json Normal file

@ -0,0 +1,24 @@
{
"private": true,
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"devDependencies": {
"dotenv": "^16.3.1",
"eslint": "^8.48.0",
"express": "^4.18.2",
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"tsconfig": "workspace:*",
"turbo": "latest"
},
"packageManager": "pnpm@8.9.0",
"name": "proxy",
"dependencies": {
"@types/express": "^4.17.21",
"infisical-node": "^1.5.0"
}
}

@ -0,0 +1,3 @@
# `@turbo/eslint-config`
Collection of internal eslint configurations.

@ -0,0 +1,34 @@
const { resolve } = require("node:path");
const project = resolve(process.cwd(), "tsconfig.json");
/*
* This is a custom ESLint configuration for use with
* typescript packages.
*
* This config extends the Vercel Engineering Style Guide.
* For more information, see https://github.com/vercel/style-guide
*
*/
module.exports = {
extends: [
"@vercel/style-guide/eslint/node",
"@vercel/style-guide/eslint/typescript",
].map(require.resolve),
parserOptions: {
project,
},
globals: {
React: true,
JSX: true,
},
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
ignorePatterns: ["node_modules/", "dist/"],
};

@ -0,0 +1,42 @@
const { resolve } = require("node:path");
const project = resolve(process.cwd(), "tsconfig.json");
/*
* This is a custom ESLint configuration for use with
* Next.js apps.
*
* This config extends the Vercel Engineering Style Guide.
* For more information, see https://github.com/vercel/style-guide
*
*/
module.exports = {
extends: [
"@vercel/style-guide/eslint/node",
"@vercel/style-guide/eslint/browser",
"@vercel/style-guide/eslint/typescript",
"@vercel/style-guide/eslint/react",
"@vercel/style-guide/eslint/next",
"eslint-config-turbo",
].map(require.resolve),
parserOptions: {
project,
},
globals: {
React: true,
JSX: true,
},
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
ignorePatterns: ["node_modules/", "dist/"],
// add rules configurations here
rules: {
"import/no-default-export": "off",
},
};

@ -0,0 +1,11 @@
{
"name": "eslint-config-custom",
"license": "MIT",
"version": "0.0.0",
"private": true,
"devDependencies": {
"@vercel/style-guide": "^5.0.0",
"eslint-config-turbo": "^1.10.12",
"typescript": "^5.2.2"
}
}

@ -0,0 +1,39 @@
const { resolve } = require("node:path");
const project = resolve(process.cwd(), "tsconfig.json");
/*
* This is a custom ESLint configuration for use with
* internal (bundled by their consumer) libraries
* that utilize React.
*
* This config extends the Vercel Engineering Style Guide.
* For more information, see https://github.com/vercel/style-guide
*
*/
module.exports = {
extends: [
"@vercel/style-guide/eslint/browser",
"@vercel/style-guide/eslint/typescript",
"@vercel/style-guide/eslint/react",
].map(require.resolve),
parserOptions: {
project,
},
globals: {
JSX: true,
},
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
ignorePatterns: ["node_modules/", "dist/", ".eslintrc.js"],
rules: {
// add specific rules configurations here
},
};

@ -0,0 +1,11 @@
{
"name": "server",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./src/index.ts",
"types": "./src/index.ts"
}

@ -0,0 +1,11 @@
import { badRequest } from "./messages/badRequest";
import { unknownRoute } from "./messages/unknownRoute";
export const RouteMessages = {
unknownRoute: unknownRoute,
badRequest: badRequest,
};
export * from "./route/route";
export * from "./route/routeManager";
export * from "./server/server";

@ -0,0 +1,10 @@
import { baseMessage } from "./baseMessage";
/**
* Creates a response for a bad request
*
* @returns the bad request message
*/
export function badRequest(message: string) {
return baseMessage(true, message);
}

@ -0,0 +1,13 @@
/**
* Creates a base message for use in JSON responses
*
* @param error the error status
* @param message the message to show
* @returns the base message
*/
export function baseMessage(error: boolean, message: string) {
return {
error: error,
message: message,
};
}

@ -0,0 +1,10 @@
import { baseMessage } from "./baseMessage";
/**
* Creates a response for an unknown route
*
* @returns the unknown route message
*/
export function unknownRoute() {
return baseMessage(true, "Unknown route");
}

@ -0,0 +1,34 @@
import { Request, Response } from "express";
type RouteType = {
/**
* The path to handle
*/
path: string;
};
export abstract class Route {
private path: string;
constructor({ path }: RouteType) {
this.path = path;
console.log(`Created route handler for ${path}`);
}
/**
* Handle the incoming request
*
* @param req the request
* @param res the response
*/
abstract handle(req: Request, res: Response): void;
/**
* Get the path of the route
*
* @returns the path
*/
getPath() {
return this.path;
}
}

@ -0,0 +1,33 @@
import { Route } from "./route";
export class RouteManager {
private routes: Route[] = [];
/**
* Add a route to the route manager
*
* @param route the route to add
*/
addRoute(route: Route) {
this.routes.push(route);
}
/**
* Get a route by path
*
* @param path the path to get the route for
* @returns the route or undefined if not found
*/
getRoute(path: string) {
return this.routes.find((route) => route.getPath() === path);
}
/**
* Get all routes
*
* @returns all routes
*/
getRoutes() {
return this.routes;
}
}

@ -0,0 +1,38 @@
import express from "express";
type ServerType = {
/**
* The port to listen on
* @default 3000
*/
port: number | string;
onLoaded?: () => void;
};
export function createServer({ port = 3000, onLoaded }: ServerType) {
if (typeof port === "string") {
port = Number(port);
if (isNaN(port)) {
throw new Error("Port must be a number");
}
}
const server = express();
// Enable JSON parsing
server.use(express.json());
// Remove the X-Powered-By header
server.disable("x-powered-by");
// Turn on ETag support (for caching)
server.enable("etag");
// Listen on the specified port
server.listen(port, () => {
console.log(`Server listening on http://localhost:${port}`);
onLoaded && onLoaded(); // Call the onLoaded callback if it exists
});
return server;
}

@ -0,0 +1,7 @@
{
"extends": "tsconfig/server.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}

@ -0,0 +1,18 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"resolveJsonModule": true,
"isolatedModules": true,
"moduleDetection": "force",
"strict": true,
"noUncheckedIndexedAccess": true,
"module": "NodeNext",
"noEmit": true,
"lib": ["es2022", "dom", "dom.iterable"]
},
"exclude": ["node_modules"]
}

@ -0,0 +1,13 @@
{
"name": "tsconfig",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"files": [
"base.json",
"server.json"
]
}

@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Server",
"extends": "./base.json"
}

@ -0,0 +1,11 @@
{
"name": "utils",
"version": "0.0.0",
"private": true,
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "./src/index.ts",
"types": "./src/index.ts"
}

@ -0,0 +1,15 @@
/**
* Checks if all environment variables are set
*
* @param variables the environment variables to check
* @returns true if all variables are set, false otherwise
*/
export function checkEnvironmentVariables(...variables: string[]): boolean {
let allVariablesSet = true;
variables.forEach((variable) => {
if (!process.env[variable]) {
throw new Error(`${variable} not set in environment variables`);
}
});
return allVariablesSet;
}

@ -0,0 +1,2 @@
export * from "./envVariables";
export * from "./secrets";

@ -0,0 +1,16 @@
import InfisicalClient from "infisical-node";
/**
* Create an infisical client
*
* @param token the infisical token
* @returns the infisical client
*/
function createInfisicalClient(token: string) {
return new InfisicalClient({
token,
siteURL: "https://secrets.fascinated.cc",
});
}
export { createInfisicalClient };

@ -0,0 +1,7 @@
{
"extends": "tsconfig/server.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}

4160
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file

@ -0,0 +1,3 @@
packages:
- "apps/*"
- "packages/*"

3
tsconfig.json Normal file

@ -0,0 +1,3 @@
{
"extends": "tsconfig/base.json"
}

15
turbo.json Normal file

@ -0,0 +1,15 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "!.next/cache/**"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
}
}
}