Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend)!: Create vitnode-backend npm package #386

Merged
merged 28 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15d28e3
feat(backend): Add nestjsMainApp function
aXenDeveloper Jun 19, 2024
413de1a
perf(backend): Add VitNodeCoreModule
aXenDeveloper Jun 19, 2024
3379f10
perf(backend): Move config to package
aXenDeveloper Jun 19, 2024
c228fea
perf(backend): Move database service to package
aXenDeveloper Jun 20, 2024
4347a43
feat(backend): Create "vitnode-backend init" script to init require r…
aXenDeveloper Jun 20, 2024
9e3f1b9
fix(backend): Fix install packages when vitnode-backend packages has …
aXenDeveloper Jun 20, 2024
4746d0e
fix(backend): Build vitnode-backend package
aXenDeveloper Jun 21, 2024
acfa95a
chore: Update packages
aXenDeveloper Jun 21, 2024
b5de3a5
fix(github): Pre-install pnpm in build workflow
aXenDeveloper Jun 21, 2024
368b52c
chore: Change pnpm version
aXenDeveloper Jun 21, 2024
1ecfbfe
perf(backend): Move nav module into package
aXenDeveloper Jun 21, 2024
62dfbe1
perf(backend): Move session module to package
aXenDeveloper Jun 21, 2024
1cef579
perf(backend): Move all guards to package
aXenDeveloper Jun 21, 2024
b6a1791
perf(backend): Move plugins module to package
aXenDeveloper Jun 21, 2024
1ea6286
perf(backend): Move nav admin service to package
aXenDeveloper Jun 22, 2024
9b80d5d
perf(backend): Move langs & plugins modules to package
aXenDeveloper Jun 22, 2024
daa1b43
perf(backend): Move users module to package
aXenDeveloper Jun 22, 2024
b3e043d
perf(backend): Move settings & middleware modules to package
aXenDeveloper Jun 22, 2024
2dc9d95
perf(backend): Move email module to package
aXenDeveloper Jun 22, 2024
3aa8f9a
fix(backend): Send emails when change config
aXenDeveloper Jun 22, 2024
924eb2e
feat(backend): Create helpers service for email
aXenDeveloper Jun 22, 2024
e5761f1
perf(backend): Add frontend url to email helper by env
aXenDeveloper Jun 22, 2024
bacaa2c
Merge branch 'canary' into apps/backend
aXenDeveloper Jun 22, 2024
9550019
chore: Change prettier config
aXenDeveloper Jun 22, 2024
d08ed45
perf(backend): Move init scripts to package
aXenDeveloper Jun 23, 2024
9e04907
perf(docs): Remove docs
aXenDeveloper Jun 23, 2024
fe7f9e7
chore: Fix path to type vitnode-backend
aXenDeveloper Jun 23, 2024
0aa27ab
chore: Update packages
aXenDeveloper Jun 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Loading