feat: add nestjs app (#172)
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -3,5 +3,7 @@
|
|||||||
{
|
{
|
||||||
"mode": "auto"
|
"mode": "auto"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"typescript.tsdk": "node_modules\\typescript\\lib",
|
||||||
|
"js/ts.implicitProjectConfig.experimentalDecorators": true
|
||||||
}
|
}
|
||||||
|
|||||||
73
apps/nestjs/README.md
Normal file
73
apps/nestjs/README.md
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||||
|
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||||
|
|
||||||
|
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||||
|
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||||
|
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||||
|
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||||
|
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||||
|
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||||
|
</p>
|
||||||
|
<!--[](https://opencollective.com/nest#backer)
|
||||||
|
[](https://opencollective.com/nest#sponsor)-->
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# development
|
||||||
|
$ npm run start
|
||||||
|
|
||||||
|
# watch mode
|
||||||
|
$ npm run start:dev
|
||||||
|
|
||||||
|
# production mode
|
||||||
|
$ npm run start:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# unit tests
|
||||||
|
$ npm run test
|
||||||
|
|
||||||
|
# e2e tests
|
||||||
|
$ npm run test:e2e
|
||||||
|
|
||||||
|
# test coverage
|
||||||
|
$ npm run test:cov
|
||||||
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||||
|
|
||||||
|
## Stay in touch
|
||||||
|
|
||||||
|
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||||
|
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||||
|
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Nest is [MIT licensed](LICENSE).
|
||||||
4
apps/nestjs/nest-cli.json
Normal file
4
apps/nestjs/nest-cli.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
||||||
58
apps/nestjs/package.json
Normal file
58
apps/nestjs/package.json
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"name": "@homarr/nest",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "pnpm with-env vite",
|
||||||
|
"prebuild": "rimraf dist",
|
||||||
|
"build": "vite build",
|
||||||
|
"start": "nest start",
|
||||||
|
"start:dev": "nest start --watch",
|
||||||
|
"start:debug": "nest start --debug --watch",
|
||||||
|
"start:prod": "node dist/main",
|
||||||
|
"clean": "rm -rf .turbo node_modules",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
|
"with-env": "dotenv -e ../../.env --"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
|
"@homarr/log": "workspace:^0.1.0",
|
||||||
|
"@nestjs/common": "^10.3.3",
|
||||||
|
"@nestjs/core": "^10.3.3",
|
||||||
|
"@nestjs/platform-express": "^10.3.3",
|
||||||
|
"nest-winston": "^1.9.4",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rxjs": "^7.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
|
"@nestjs/cli": "^10.3.2",
|
||||||
|
"@nestjs/schematics": "^10.1.1",
|
||||||
|
"@nestjs/testing": "^10.3.3",
|
||||||
|
"@swc/core": "^1.2.155",
|
||||||
|
"@types/express": "^4.17.13",
|
||||||
|
"@types/node": "^20.11.24",
|
||||||
|
"@types/supertest": "^2.0.11",
|
||||||
|
"eslint": "^8.57.0",
|
||||||
|
"prettier": "^3.2.5",
|
||||||
|
"supertest": "^6.1.3",
|
||||||
|
"ts-node": "^10.0.0",
|
||||||
|
"tsconfig-paths": "^3.10.1",
|
||||||
|
"typescript": "^5.3.3",
|
||||||
|
"vite": "^4.0.4",
|
||||||
|
"vite-plugin-node": "^3.1.0"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"extends": [
|
||||||
|
"@homarr/eslint-config/base"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"prettier": "@homarr/prettier-config"
|
||||||
|
}
|
||||||
39
apps/nestjs/src/app.controller.spec.ts
Normal file
39
apps/nestjs/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
import type { TestingModule } from "@nestjs/testing";
|
||||||
|
import { Test } from "@nestjs/testing";
|
||||||
|
import { beforeEach, describe, expect, it, vitest } from "vitest";
|
||||||
|
|
||||||
|
import { AppController } from "./app.controller";
|
||||||
|
import { AppService } from "./app.service";
|
||||||
|
import { DatabaseService } from "./db/database.service";
|
||||||
|
|
||||||
|
describe("AppController", () => {
|
||||||
|
let appController: AppController;
|
||||||
|
let appService: AppService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const app: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService, DatabaseService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
appController = app.get<AppController>(AppController);
|
||||||
|
appService = app.get<AppService>(AppService);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("root", () => {
|
||||||
|
it('should return "Hello World!"', async () => {
|
||||||
|
// arrange
|
||||||
|
vitest
|
||||||
|
.spyOn(appService, "getHello")
|
||||||
|
.mockReturnValueOnce(Promise.resolve("ABC"));
|
||||||
|
|
||||||
|
// act
|
||||||
|
const a = await appController.getHello();
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(a).toBe("ABC");
|
||||||
|
expect(appService.getHello).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
19
apps/nestjs/src/app.controller.ts
Normal file
19
apps/nestjs/src/app.controller.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Controller, Get, Inject } from "@nestjs/common";
|
||||||
|
|
||||||
|
import { AppService } from "./app.service";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
// @ts-expect-error decorators are not correctly handled yet
|
||||||
|
constructor(@Inject(AppService) private readonly appService: AppService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async getHello(): Promise<string> {
|
||||||
|
return await this.appService.getHello();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("/random")
|
||||||
|
getRandom(): string {
|
||||||
|
return Math.random().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
apps/nestjs/src/app.module.ts
Normal file
12
apps/nestjs/src/app.module.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Module } from "@nestjs/common";
|
||||||
|
|
||||||
|
import { AppController } from "./app.controller";
|
||||||
|
import { AppService } from "./app.service";
|
||||||
|
import { DatabaseService } from "./db/database.service";
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [DatabaseService, AppService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
16
apps/nestjs/src/app.service.ts
Normal file
16
apps/nestjs/src/app.service.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Inject, Injectable } from "@nestjs/common";
|
||||||
|
|
||||||
|
import { DatabaseService } from "./db/database.service";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AppService {
|
||||||
|
constructor(
|
||||||
|
// @ts-expect-error decorators are not correctly handled yet
|
||||||
|
@Inject(DatabaseService) private readonly databaseService: DatabaseService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async getHello(): Promise<string> {
|
||||||
|
const users = await this.databaseService.get().query.users.findMany();
|
||||||
|
return JSON.stringify(users);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
apps/nestjs/src/db/database.service.ts
Normal file
10
apps/nestjs/src/db/database.service.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
|
||||||
|
import { db } from "@homarr/db";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DatabaseService {
|
||||||
|
get() {
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
apps/nestjs/src/main.ts
Normal file
27
apps/nestjs/src/main.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { NestFactory } from "@nestjs/core";
|
||||||
|
import { WinstonModule } from "nest-winston";
|
||||||
|
|
||||||
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
|
import { AppModule } from "./app.module";
|
||||||
|
|
||||||
|
const winstonLoggerModule = WinstonModule.createLogger({
|
||||||
|
instance: logger,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.create(AppModule, {
|
||||||
|
logger: winstonLoggerModule,
|
||||||
|
});
|
||||||
|
await app.listen(3100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-expect-error this has no type yet
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
|
if (import.meta.env.PROD) {
|
||||||
|
void bootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const viteNodeApp = NestFactory.create(AppModule, {
|
||||||
|
logger: winstonLoggerModule,
|
||||||
|
});
|
||||||
4
apps/nestjs/tsconfig.build.json
Normal file
4
apps/nestjs/tsconfig.build.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "dist", "**/*spec.ts"]
|
||||||
|
}
|
||||||
19
apps/nestjs/tsconfig.json
Normal file
19
apps/nestjs/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"declaration": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"strict": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"incremental": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*", "vite.config.ts"]
|
||||||
|
}
|
||||||
34
apps/nestjs/vite.config.ts
Normal file
34
apps/nestjs/vite.config.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import { VitePluginNode } from "vite-plugin-node";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [
|
||||||
|
...VitePluginNode({
|
||||||
|
adapter: "nest",
|
||||||
|
appPath: "./src/main.ts",
|
||||||
|
tsCompiler: "swc",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
optimizeDeps: {
|
||||||
|
// Vite does not work well with optionnal dependencies,
|
||||||
|
// mark them as ignored for now
|
||||||
|
exclude: [
|
||||||
|
"@nestjs/microservices",
|
||||||
|
"@nestjs/websockets",
|
||||||
|
"cache-manager",
|
||||||
|
"class-transformer",
|
||||||
|
"class-validator",
|
||||||
|
"fastify-swagger",
|
||||||
|
],
|
||||||
|
esbuildOptions: {
|
||||||
|
tsconfigRaw: {
|
||||||
|
compilerOptions: {
|
||||||
|
experimentalDecorators: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
port: 3100,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@homarr/db",
|
"name": "@homarr/db",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./client": "./client.ts",
|
"./client": "./client.ts",
|
||||||
|
|||||||
2041
pnpm-lock.yaml
generated
2041
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
plugins: ["@typescript-eslint", "import"],
|
plugins: ["@typescript-eslint", "import"],
|
||||||
rules: {
|
rules: {
|
||||||
|
"@typescript-eslint/prefer-nullish-coalescing": "off",
|
||||||
"turbo/no-undeclared-env-vars": "off",
|
"turbo/no-undeclared-env-vars": "off",
|
||||||
"@typescript-eslint/no-unused-vars": [
|
"@typescript-eslint/no-unused-vars": [
|
||||||
"error",
|
"error",
|
||||||
|
|||||||
Reference in New Issue
Block a user