Skip to content

Commit

Permalink
Merge pull request #386 from aXenDeveloper/apps/backend
Browse files Browse the repository at this point in the history
feat(backend)!: Create vitnode-backend npm package
  • Loading branch information
aXenDeveloper authored Jun 23, 2024
2 parents 3cdd7df + 0aa27ab commit 2f2f547
Show file tree
Hide file tree
Showing 786 changed files with 7,130 additions and 7,880 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/checkout@v4
with:
node-version: 20
fetch-depth: 2

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false
version: 9.4.0

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"singleQuote": false,
"arrowParens": "avoid",
"trailingComma": "none",
"trailingComma": "all",
"printWidth": 80,
"plugins": ["prettier-plugin-tailwindcss"],
"tailwindFunctions": ["cn"]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<h1 align="center">
<p align="center">
<br>
<a href="https://vitnode.com/" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="apps/docs/public/assets/vitnode_logo_dark.svg">
<source media="(prefers-color-scheme: light)" srcset="apps/docs/public/assets/vitnode_logo_light.svg">
<img alt="VitNode Logo" src="apps/docs/public/assets/vitnode_logo_light.svg" width="600">
<img alt="VitNode Logo" src="apps/docs/public/assets/vitnode_logo_light.svg" width="400">
</picture>
</a>
<br>
<br>
</h1>
</p>

# VitNode

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:20-alpine AS base
RUN npm i -g pnpm@9.3.0
RUN npm i -g pnpm@9.4.0

FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
Expand Down
18 changes: 9 additions & 9 deletions apps/backend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as dotenv from "dotenv";

if (process.env.NODE_ENV === "production") {
dotenv.config({
path: join(process.cwd(), "..", "..", ".env")
path: join(process.cwd(), "..", "..", ".env"),
});
}

Expand All @@ -16,27 +16,27 @@ const config: CodegenConfig = {
overwrite: true,
schema: `${graphql_url}/graphql`,
documents: [
join(process.cwd(), "..", "frontend", "plugins/**/graphql/**/*.gql")
join(process.cwd(), "..", "frontend", "plugins/**/graphql/**/*.gql"),
],
generates: {
[`${join(process.cwd(), "..", "frontend", "graphql", "hooks.ts")}`]: {
plugins: [
"typescript",
"typescript-operations",
"typescript-document-nodes"
"typescript-document-nodes",
],
config: {
scalars: {
DateTime: "Date"
DateTime: "Date",
},
enumsAsConst: true,
allowEnumStringTypes: true,
namingConvention: {
enumValues: "change-case-all#lowerCase"
}
}
}
}
enumValues: "change-case-all#lowerCase",
},
},
},
},
};

export default config;
4 changes: 2 additions & 2 deletions apps/backend/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
dialect: "postgresql",
dbCredentials: {
...DATABASE_ENVS,
ssl: false
ssl: false,
},
schema: "./src/plugins/**/admin/database/schema/*.ts"
schema: "./src/plugins/**/admin/database/schema/*.ts",
});
12 changes: 12 additions & 0 deletions apps/backend/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { DatabaseService } from "vitnode-backend";
import { NodePgDatabase } from "drizzle-orm/node-postgres";

import { schemaDatabase } from "@/database/schema";

// Overwrite the DatabaseService class to include the db property
declare module "vitnode-backend" {
export declare class DatabaseService {
db: NodePgDatabase<typeof schemaDatabase>;
}
}
35 changes: 10 additions & 25 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"license": "GPL-3.0 license",
"scripts": {
"db": "drizzle-kit push",
"config:database": "ts-node ./src/utils/actions/finish-build.ts",
"config:init": "source ../../.env && NEXT_PUBLIC_FRONTEND_URL=$NEXT_PUBLIC_FRONTEND_URL DB_HOST=$DB_HOST DB_PORT=$DB_PORT DB_USER=$DB_USER DB_PASSWORD=$DB_PASSWORD DB_DATABASE=$DB_DATABASE vitnode-backend init",
"build": "nest build",
"dev": "pnpm config:database && cross-env NODE_ENV=development nest start -w",
"dev": "pnpm config:init && cross-env NODE_ENV=development nest start -w",
"email:dev": "email dev -p 3001",
"start": "nest start",
"start:debug": "nest start --debug --watch",
Expand All @@ -20,59 +20,44 @@
"codegen": "graphql-codegen --config codegen.ts"
},
"dependencies": {
"@apollo/server": "^4.10.4",
"@nestjs/apollo": "^12.1.0",
"@nestjs/common": "^10.3.9",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.9",
"@nestjs/graphql": "^12.1.1",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/schedule": "^4.0.2",
"@nestjs/serve-static": "^4.0.2",
"@react-email/components": "^0.0.19",
"@react-email/render": "^0.0.15",
"bcrypt": "^5.1.1",
"express": "^4.19.2",
"graphql": "^16.8.2",
"nodemailer": "^6.9.13",
"graphql": "^16.9.0",
"react": "^18.3.1",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"sharp": "^0.33.4",
"tar": "^7.2.0"
"rxjs": "^7.8.1"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/typescript": "^4.0.7",
"@graphql-codegen/typescript-document-nodes": "^4.0.7",
"@graphql-codegen/typescript-operations": "^4.2.1",
"@nestjs/cli": "^10.3.2",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/schematics": "^10.1.1",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.6.1",
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.7",
"@swc/cli": "^0.3.14",
"@swc/core": "^1.6.5",
"@types/express": "^4.17.21",
"@types/node": "^20.14.2",
"@types/nodemailer": "^6.4.15",
"@types/node": "^20.14.8",
"@types/pg": "^8.11.6",
"@types/react": "^18.3.3",
"vitnode-backend": "workspace:*",
"@vitnode/shared": "workspace:*",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cookie-parser": "^1.4.6",
"cross-env": "^7.0.3",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.22.7",
"drizzle-orm": "^0.31.2",
"eslint": "^8.57.0",
"eslint-config-vitnode": "workspace:*",
"pg": "^8.12.0",
"react-email": "^2.1.4",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5"
"typescript": "^5.5.2",
"vitnode-backend": "workspace:*"
}
}
42 changes: 12 additions & 30 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
import { join } from "path";

import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { JwtModule } from "@nestjs/jwt";
import { ScheduleModule } from "@nestjs/schedule";
import { GraphQLModule } from "@nestjs/graphql";
import { ApolloDriver, ApolloDriverConfig } from "@nestjs/apollo";
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
import { ServeStaticModule } from "@nestjs/serve-static";
import { Ctx } from "vitnode-backend";
import { VitNodeCoreModule } from "vitnode-backend";

import { DatabaseModule } from "./database/database.module";
import { PluginsModule } from "./plugins/plugins.module";
import { ABSOLUTE_PATHS, configForAppModule } from "./config";
import { DATABASE_ENVS } from "./database/client";
import { schemaDatabase } from "./database/schema";

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [configForAppModule],
envFilePath: join(process.cwd(), "..", "..", ".env")
VitNodeCoreModule.register({
paths: {
envFile: join(process.cwd(), "..", "..", ".env"),
},
database: {
config: DATABASE_ENVS,
schemaDatabase,
},
}),
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), "schema.gql"),
sortSchema: true,
playground: false,
plugins: [ApolloServerPluginLandingPageLocalDefault()],
context: ({ req, res }): Ctx => ({ req, res })
}),
JwtModule.register({ global: true }),
ServeStaticModule.forRoot({
rootPath: join(ABSOLUTE_PATHS.uploads.public),
serveRoot: "/public/"
}),
ScheduleModule.forRoot(),
PluginsModule,
DatabaseModule
]
],
})
export class AppModule {}
Loading

0 comments on commit 2f2f547

Please sign in to comment.