Skip to content

Commit

Permalink
chore:使用 nest -h 生成不同的模块
Browse files Browse the repository at this point in the history
  • Loading branch information
18895684046 committed Sep 24, 2022
1 parent 0f49416 commit 8176f32
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"nanoid": "^4.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
Expand Down
11 changes: 8 additions & 3 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Param } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
constructor(private readonly appService: AppService) { }

@Get()
getHello(): string {
return this.appService.getHello();
}
@Get('/list')
getSwipList():any[]{
getSwipList(): any[] {
return this.appService.getSwipList();
}
@Get(':id')
// @Param('id') 有参数的话,返回的就是没有被序列化的值 --> 没有参数的话,会自动序列化
say(@Param('id') id: string): string {
return id
}
}
11 changes: 8 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Module } from '@nestjs/common';
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { CatModule } from './cat/cat.module';

@Module({
imports: [],
imports: [CatModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
export class AppModule {
// configure(consumer:MiddlewareConsumer){
// consumer.apply().forRoutes()
// }
}
22 changes: 13 additions & 9 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { Injectable } from '@nestjs/common';
interface Swipe {
name:string,
imgUrl:string
uuid: number,
imgUrl: string
}
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
getSwipList():Swipe[]{
getSwipList(): Swipe[] {
const imgList = [
{
name:"第一张数据11",
imgUrl:"test11"
uuid: Math.random() * 6,
imgUrl: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F210F2130512J47-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1665481740&t=0bfa9f3d1f071e8381f14a1e858fa2d6"
},
{
name:"第一张",
imgUrl:"test"
uuid: Math.random() * 6,
imgUrl: "https://img1.baidu.com/it/u=1546227440,2897989905&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"
},
{
name:"第一张",
imgUrl:"test"
uuid: Math.random() * 6,
imgUrl: "https://img0.baidu.com/it/u=747797291,1321739150&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500"
},
{
uuid: Math.random() * 6,
imgUrl: "https://img0.baidu.com/it/u=3643895624,2552772604&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=675"
},
]
return imgList
Expand Down
18 changes: 18 additions & 0 deletions src/cat/cat.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CatController } from './cat.controller';

describe('CatController', () => {
let controller: CatController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [CatController],
}).compile();

controller = module.get<CatController>(CatController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
5 changes: 5 additions & 0 deletions src/cat/cat.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Controller } from '@nestjs/common';

@Controller('cat')
export class CatController {
}
7 changes: 7 additions & 0 deletions src/cat/cat.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { CatController } from './cat.controller';

@Module({
controllers: [CatController]
})
export class CatModule {}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
app.enableCors();//node设置跨域
await app.listen(5000);
}
bootstrap();

0 comments on commit 8176f32

Please sign in to comment.