updated
This commit is contained in:
parent
388b42556b
commit
e452723e0f
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
combined.log
|
||||||
|
error.log
|
9
.env.development
Normal file
9
.env.development
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
JWT_SECRET=sajdhgjhasdhgads
|
||||||
|
EMAIL_HOST=smtp.gmail.com
|
||||||
|
EMAIL_PORT=587
|
||||||
|
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||||
|
EMAIL_PASSWORD=123456
|
||||||
|
PORT=3000
|
||||||
|
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||||
|
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
|
||||||
|
JWT_EXPIRATION_MINUTES=300
|
9
.env.production
Normal file
9
.env.production
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
JWT_SECRET=sajdhgjhasdhgads
|
||||||
|
EMAIL_HOST=smtp.gmail.com
|
||||||
|
EMAIL_PORT=587
|
||||||
|
EMAIL_USERNAME=krish@sentientgeeks.com
|
||||||
|
EMAIL_PASSWORD=123456
|
||||||
|
PORT=3000
|
||||||
|
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
|
||||||
|
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
|
||||||
|
JWT_EXPIRATION_MINUTES=300
|
@ -2,6 +2,7 @@ module.exports = {
|
|||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
project: 'tsconfig.json',
|
project: 'tsconfig.json',
|
||||||
|
tsconfigRootDir: __dirname,
|
||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
},
|
},
|
||||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||||
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
# compiled output
|
# compiled output
|
||||||
/dist
|
/dist
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/build
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
@ -33,3 +34,23 @@ lerna-debug.log*
|
|||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# temp directory
|
||||||
|
.temp
|
||||||
|
.tmp
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
FROM node:latest
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
<p align="center">
|
<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>
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||||
|
29
docker-compose.dev.yml
Normal file
29
docker-compose.dev.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
node:
|
||||||
|
container_name: nodejs-api
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=development
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
mongo:
|
||||||
|
container_name: mongodb
|
||||||
|
image: mongo:latest
|
||||||
|
ports:
|
||||||
|
- "27017:27017"
|
||||||
|
volumes:
|
||||||
|
- mongo_data:/data/db
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mongo_data:
|
30
docker-compose.prod.yml
Normal file
30
docker-compose.prod.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
node:
|
||||||
|
container_name: nodejs-api
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
depends_on:
|
||||||
|
- mongo
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
mongo:
|
||||||
|
container_name: mongodb
|
||||||
|
image: mongo:latest
|
||||||
|
ports:
|
||||||
|
- "27017:27017"
|
||||||
|
volumes:
|
||||||
|
- mongo_data:/data/db
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mongo_data:
|
@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
"collection": "@nestjs/schematics",
|
"collection": "@nestjs/schematics",
|
||||||
"sourceRoot": "src"
|
"sourceRoot": "src",
|
||||||
|
"compilerOptions": {
|
||||||
|
"deleteOutDir": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
11656
package-lock.json
generated
11656
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
61
package.json
61
package.json
@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "cp-node-backend",
|
"name": "nest-demo",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "rimraf dist",
|
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
@ -21,37 +20,37 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^8.0.0",
|
"@nestjs/common": "^10.0.0",
|
||||||
"@nestjs/core": "^8.0.0",
|
"@nestjs/core": "^10.0.0",
|
||||||
"@nestjs/mongoose": "^9.0.1",
|
"@nestjs/platform-express": "^10.0.0",
|
||||||
"@nestjs/platform-express": "^8.0.0",
|
"@nestjs/typeorm": "^10.0.2",
|
||||||
"mongoose": "^6.0.12",
|
"mysql2": "^3.9.2",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rimraf": "^3.0.2",
|
"rxjs": "^7.8.1",
|
||||||
"rxjs": "^7.2.0"
|
"typeorm": "^0.3.20"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^8.0.0",
|
"@nestjs/cli": "^10.0.0",
|
||||||
"@nestjs/schematics": "^8.0.0",
|
"@nestjs/schematics": "^10.0.0",
|
||||||
"@nestjs/testing": "^8.0.0",
|
"@nestjs/testing": "^10.0.0",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.17",
|
||||||
"@types/jest": "^27.0.1",
|
"@types/jest": "^29.5.2",
|
||||||
"@types/node": "^16.0.0",
|
"@types/node": "^20.3.1",
|
||||||
"@types/supertest": "^2.0.11",
|
"@types/supertest": "^6.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||||
"@typescript-eslint/parser": "^5.0.0",
|
"@typescript-eslint/parser": "^6.0.0",
|
||||||
"eslint": "^8.0.1",
|
"eslint": "^8.42.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^5.0.0",
|
||||||
"jest": "^27.2.5",
|
"jest": "^29.5.0",
|
||||||
"prettier": "^2.3.2",
|
"prettier": "^3.0.0",
|
||||||
"source-map-support": "^0.5.20",
|
"source-map-support": "^0.5.21",
|
||||||
"supertest": "^6.1.3",
|
"supertest": "^6.3.3",
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "^29.1.0",
|
||||||
"ts-loader": "^9.2.3",
|
"ts-loader": "^9.4.3",
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.9.1",
|
||||||
"tsconfig-paths": "^3.10.1",
|
"tsconfig-paths": "^4.2.0",
|
||||||
"typescript": "^4.3.5"
|
"typescript": "^5.1.3"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"moduleFileExtensions": [
|
"moduleFileExtensions": [
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { UserModule } from './user/user.module';
|
import { AuthModule } from './auth/auth.module';
|
||||||
import { SchoolModule } from './school/school.module';
|
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [UserModule, SchoolModule,MongooseModule.forRoot('mongodb://localhost/classpoint')],
|
imports: [AuthModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
18
src/auth/auth.controller.spec.ts
Normal file
18
src/auth/auth.controller.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { AuthController } from './auth.controller';
|
||||||
|
|
||||||
|
describe('AuthController', () => {
|
||||||
|
let controller: AuthController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [AuthController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<AuthController>(AuthController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
4
src/auth/auth.controller.ts
Normal file
4
src/auth/auth.controller.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { Controller } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Controller('auth')
|
||||||
|
export class AuthController {}
|
9
src/auth/auth.module.ts
Normal file
9
src/auth/auth.module.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AuthController } from './auth.controller';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [AuthController],
|
||||||
|
providers: [AuthService]
|
||||||
|
})
|
||||||
|
export class AuthModule {}
|
18
src/auth/auth.service.spec.ts
Normal file
18
src/auth/auth.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
describe('AuthService', () => {
|
||||||
|
let service: AuthService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [AuthService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<AuthService>(AuthService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
4
src/auth/auth.service.ts
Normal file
4
src/auth/auth.service.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AuthService {}
|
4
src/auth/dto/auth.dto.ts
Normal file
4
src/auth/dto/auth.dto.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export class AuthDto {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
13
src/auth/strategies/accessToken.strategy.ts
Normal file
13
src/auth/strategies/accessToken.strategy.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
@injectable()
|
||||||
|
export default class AccessTokenStrategy extends PassportStrategy(
|
||||||
|
Strategy,
|
||||||
|
'access-token',
|
||||||
|
) {
|
||||||
|
constructor(private readonly authService: AuthService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(payload: any) {
|
||||||
|
return this.authService.validateAccessToken(payload);
|
||||||
|
}
|
||||||
|
}
|
13
src/auth/strategies/refreshToken.strategy.ts
Normal file
13
src/auth/strategies/refreshToken.strategy.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
@injectable()
|
||||||
|
export default class RefreshTokenStrategy extends PassportStrategy(
|
||||||
|
Strategy,
|
||||||
|
'refresh-token',
|
||||||
|
) {
|
||||||
|
constructor(private readonly authService: AuthService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(payload: any) {
|
||||||
|
return this.authService.validateRefreshToken(payload);
|
||||||
|
}
|
||||||
|
}
|
7
src/common/constants/main.ts
Normal file
7
src/common/constants/main.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
expect const mail = {
|
||||||
|
from: ' ',
|
||||||
|
to: ' ',
|
||||||
|
subject: ' ',
|
||||||
|
text: ' ',
|
||||||
|
html: ' ',
|
||||||
|
};
|
5
src/common/guards/accessToken.guard.ts
Normal file
5
src/common/guards/accessToken.guard.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export class AccessToken extends AuthGuard('access-token') {}
|
||||||
|
|
||||||
|
function AuthGuard(arg0: string) {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
}
|
5
src/common/guards/refreshToken.guard.ts
Normal file
5
src/common/guards/refreshToken.guard.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export class RefreshTokenGuard extends AuthGuard('refresh-token') {}
|
||||||
|
|
||||||
|
function AuthGuard(arg0: string) {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
}
|
@ -3,7 +3,6 @@ import { AppModule } from './app.module';
|
|||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
app.enableCors(); // Unable cors
|
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"target": "es2017",
|
"target": "ES2021",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user