Skip to content

Commit

Permalink
Adds api
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed May 15, 2024
1 parent 2623466 commit 2ac6ef6
Show file tree
Hide file tree
Showing 717 changed files with 44,868 additions and 969 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REVERSE_PROXY_PORT=8000
REVERSE_PROXY_UI_PORT=8080
CFG_VERSION=latest
CGW_VERSION=latest
TXS_VERSION=latest
UI_VERSION=latest
RPC_NODE_URL=http://host.docker.internal:8545
ETHEREUM_NODE_URL=http://host.docker.internal:8545
41 changes: 41 additions & 0 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
MONGODB_URI="mongodb://root:root@localhost:27017/api?authSource=admin&ssl=false"
MONGODB_URI_TEST_OVERRIDE="mongodb://root:root@localhost:27017/api_test?authSource=admin&ssl=false"
MONGODB_NAME="api"
MONGODB_USER="root"
MONGODB_PASSWORD="root"
AUTH_URL="https://local.auth.thx.network"
API_URL="https://localhost:3001"
DASHBOARD_URL="https://localhost:8082"
WALLET_URL="https://localhost:8083"
WIDGET_URL="https://localhost:8080"
HARDHAT_RPC="https://localhost:8547"
HARDHAT_RPC_TEST_OVERRIDE="http://localhost:8545"
POLYGON_RPC=""
ETHEREUM_RPC=""
PRIVATE_KEY="0x873c254263b17925b686f971d7724267710895f1585bb0533db8e693a2af32ff"
INITIAL_ACCESS_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PORT="3000"
AUTH_CLIENT_ID="ISsh6Xw6wDISihJS2xs2_"
AUTH_CLIENT_SECRET="BnQrAHSb4UDnpR-9klfFAQbZvq_RjVZgLTKwRD3qfOjawX21jrnbBxvSOU84EwqAy1J-fNKvxD2qZen5Gm8jXg"
INFURA_PROJECT_ID=""
INFURA_IPFS_PROJECT_ID=""
INFURA_IPFS_PROJECT_SECRET=""
RATE_LIMIT_REWARD_GIVE="100"
RATE_LIMIT_REWARD_GIVE_WINDOW="900"
MAX_FEE_PER_GAS="400"
POLYGON_NAME="maticdev"
POLYGON_MUMBAI_NAME="mumbaidev"
SAFE_TXS_SERVICE="http://localhost:8000/txs"
HARDHAT_NAME="hardhat"
AWS_ACCESS_KEY_ID=""
AWS_SECRET_ACCESS_KEY=""
AWS_S3_PUBLIC_BUCKET_NAME="local-thx-storage-bucket"
AWS_S3_PUBLIC_BUCKET_REGION="eu-west-3"
AWS_S3_PRIVATE_BUCKET_NAME="local-thx-private-storage-bucket"
AWS_S3_PRIVATE_BUCKET_REGION="eu-west-3"
POLYGON_RELAYER=""
POLYGON_RELAYER_API_KEY=""
POLYGON_RELAYER_API_SECRET=""
LOCAL_CERT="../../certs/localhost.crt"
LOCAL_CERT_KEY="../../certs/localhost.key"
CWD="/usr/src/app/apps/api/src/"
18 changes: 18 additions & 0 deletions apps/api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
60 changes: 60 additions & 0 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#####################################################################################################
## Develop stage
#####################################################################################################
FROM node:16-slim AS develop

WORKDIR /usr/src/app

ENV NODE_OPTIONS="--max_old_space_size=8192"

RUN apt-get update \
&& apt-get install -y g++ make python3-pip build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

COPY package.json yarn.lock ./
RUN yarn
COPY . .

CMD [ "npx", "nx", "serve", "api" ]

#####################################################################################################
## Build stage
#####################################################################################################
FROM node:16-slim AS build

ENV NODE_ENV=production

WORKDIR /usr/src/app
COPY --from=develop ./usr/src/app/ ./
RUN npx nx build api --prod
COPY ./newrelic.js ./yarn.lock ./dist/apps/api/
COPY ./libs/contracts/exports ./dist/apps/api/libs/contracts/exports

#####################################################################################################
## Production stage
#####################################################################################################
FROM node:16-slim AS production

ENV NODE_ENV=production

WORKDIR /usr/src/app
COPY --from=build ./usr/src/app/dist/apps/api/package.json ./usr/src/app/dist/apps/api/yarn.lock ./

# Install dependencies and packages
RUN apt-get update \
&& apt-get install -y g++ make python3-pip build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Install your application dependencies (assuming it uses Node.js)
RUN yarn

# Clean up unnecessary packages and files
RUN apt-get purge -y --auto-remove build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

COPY --from=build ./usr/src/app/dist/apps/api ./

CMD [ "main.js" ]
11 changes: 11 additions & 0 deletions apps/api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'api',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/api',
};
20 changes: 20 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@thxnetwork/api",
"contributors": [
"Peter Polman <[email protected]>",
"Valeria Grazzini <[email protected]>",
"GarfDev <[email protected]>",
"Bram Rongen <[email protected]>",
"Justina Mary <[email protected]>",
"Evert Kors <[email protected]>",
"jochemvn <[email protected]>"
],
"license": "AGPL-3.0",
"version": "1.52.132",
"scripts": {
"migrate": "yarn run migrate:db && yarn run migrate:contracts",
"migrate:contracts": "node upgradeContractsToLatest.js",
"migrate:db": "node migrate-mongo.js up",
"migrate:db:down": "node migrate-mongo.js down"
}
}
111 changes: 111 additions & 0 deletions apps/api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"name": "api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/api/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets", "apps/api/src/app/migrations"],
"webpackConfig": "apps/api/webpack.config.js",
"generatePackageJson": true,
"additionalEntryPoints": [
{
"entryPath": "apps/api/scripts/upgradeContractsToLatest.ts",
"entryName": "upgradeContractsToLatest"
},
{
"entryPath": "apps/api/scripts/migrate-mongo.ts",
"entryName": "migrate-mongo"
},
{
"entryPath": "apps/api/scripts/script.ts",
"entryName": "script"
}
]
},
"configurations": {
"development": {},
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false
}
}
},
"serve": {
"executor": "@nx/js:node",
"options": {
"buildTarget": "api:build",
"host": "localhost",
"port": 3000,
"inspect": false,
"watch": true
},
"configurations": {
"production": {
"buildTarget": "api:build:production"
}
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/api/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/api/jest.config.ts",
"testTimeout": 60000,
"passWithNoTests": false,
"bail": true,
"runInBand": true,
"logHeapUsage": true
}
},
"script": {
"dependsOn": ["^build"],
"executor": "nx:run-commands",
"options": {
"command": "node script.js",
"cwd": "dist/apps/api"
}
},
"migrate-contracts": {
"dependsOn": ["^build"],
"executor": "nx:run-commands",
"options": {
"command": "node upgradeContractsToLatest.js",
"cwd": "dist/apps/api"
}
},
"migrate-db": {
"dependsOn": ["^build"],
"executor": "nx:run-commands",
"options": {
"command": "node migrate-mongo.js up",
"cwd": "dist/apps/api"
}
},
"migrate-db-create": {
"executor": "nx:run-commands",
"options": {
"command": "migrate-mongo create -f src/app/config/migrate-mongo-create-only.json",
"cwd": "apps/api"
}
}
}
}
4 changes: 4 additions & 0 deletions apps/api/scripts/migrate-mongo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { migrateMongoScript } from '@thxnetwork/common/index';
import migrateMongoConfig from '../src/app/config/migrate-mongo';

migrateMongoScript(migrateMongoConfig);
23 changes: 23 additions & 0 deletions apps/api/scripts/script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import db from '@thxnetwork/api/util/database';
import main from './src/veLiquidity';
// import main from './src/veTransfer';
// import main from './src/veRewards';
// import main from './src/time';
// import main from './src/galachain';
// import main from './src/sdk';
// import main from './src/vethx';
// import main from './src/safe';
// import main from './src/ipfs';
// import main from './src/invoices';
// import main from './src/demo';
// import main from './src/preview';
// import main from './src/metamask';

db.connect(process.env.MONGODB_URI_PROD);

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Loading

0 comments on commit 2ac6ef6

Please sign in to comment.