init(migration): setup boilerplate code
This commit is contained in:
commit
e6b2bfb418
5
nest-cli.json
Normal file
5
nest-cli.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
68
package.json
Normal file
68
package.json
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"name": "@habbilfr/server",
|
||||||
|
"main": "./dist/index.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"scripts": {
|
||||||
|
"prebuild": "rm -rf dist",
|
||||||
|
"build": "nest build",
|
||||||
|
"start": "nest start",
|
||||||
|
"start:dev": "nest start --watch",
|
||||||
|
"start:debug": "nest start --debug --watch",
|
||||||
|
"start:prod": "node dist/main",
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
|
"test:cov": "jest --coverage",
|
||||||
|
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||||
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@nestjs/common": "^10.1.0",
|
||||||
|
"@nestjs/core": "^10.1.0",
|
||||||
|
"@nestjs/platform-socket.io": "10.1.0",
|
||||||
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
|
"@nestjs/websockets": "10.1.0",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rxjs": "^7.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nestjs/cli": "^10.1.10",
|
||||||
|
"@nestjs/schematics": "^10.0.1",
|
||||||
|
"@nestjs/testing": "^10.1.0",
|
||||||
|
"@types/node": "^20.4.2",
|
||||||
|
"@types/supertest": "^2.0.12",
|
||||||
|
"@types/jest": "^29.5.2",
|
||||||
|
"@types/express": "^4.17.13",
|
||||||
|
"jest": "^29.5.0",
|
||||||
|
"supertest": "^6.3.3",
|
||||||
|
"source-map-support": "^0.5.20",
|
||||||
|
"ts-jest": "^29.1.1",
|
||||||
|
"ts-loader": "^9.4.4",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"tsconfig-paths": "^4.2.0",
|
||||||
|
"typescript": "^5.1.6"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"socket.io": "4.7.1"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"js",
|
||||||
|
"json",
|
||||||
|
"ts"
|
||||||
|
],
|
||||||
|
"rootDir": "src",
|
||||||
|
"testRegex": ".*\\.spec\\.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
},
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"**/*.(t|j)s"
|
||||||
|
],
|
||||||
|
"coverageDirectory": "../coverage",
|
||||||
|
"testEnvironment": "node"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
|
}
|
10
src/app.module.ts
Normal file
10
src/app.module.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Module } from '@nestjs/common'
|
||||||
|
|
||||||
|
import { GatewayModule } from './gateway/gateway.module'
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [GatewayModule],
|
||||||
|
controllers: [],
|
||||||
|
providers: []
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
8
src/gateway/gateway.module.ts
Normal file
8
src/gateway/gateway.module.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Module } from '@nestjs/common'
|
||||||
|
|
||||||
|
import { MyGateway } from './gateway'
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [MyGateway]
|
||||||
|
})
|
||||||
|
export class GatewayModule {}
|
26
src/gateway/gateway.ts
Normal file
26
src/gateway/gateway.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import type { OnModuleInit } from '@nestjs/common'
|
||||||
|
import { ConnectedSocket, MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer } from '@nestjs/websockets'
|
||||||
|
import type { Server, Socket } from 'socket.io'
|
||||||
|
|
||||||
|
@WebSocketGateway({ cors: { origin: '*' } })
|
||||||
|
export class MyGateway implements OnModuleInit {
|
||||||
|
@WebSocketServer()
|
||||||
|
server: Server
|
||||||
|
|
||||||
|
onModuleInit(): void {
|
||||||
|
this.server.on('connection', (socket) => {
|
||||||
|
console.log(socket.id)
|
||||||
|
console.log('Connected')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeMessage('newMessage')
|
||||||
|
onNewMessage(@MessageBody() data: string, @ConnectedSocket() client: Socket): void {
|
||||||
|
console.log(data, client)
|
||||||
|
this.server.emit('onMessage', {
|
||||||
|
msg: 'New Message',
|
||||||
|
content: data,
|
||||||
|
client
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
10
src/main.ts
Normal file
10
src/main.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { NestFactory } from '@nestjs/core'
|
||||||
|
|
||||||
|
import { AppModule } from './app.module'
|
||||||
|
|
||||||
|
const bootstrap = async (): Promise<void> => {
|
||||||
|
const app = await NestFactory.create(AppModule)
|
||||||
|
await app.listen(3000, () => console.log('Running on Port 3000'))
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap()
|
23
test/app.e2e-spec.ts
Normal file
23
test/app.e2e-spec.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import type { TestingModule } from '@nestjs/testing'
|
||||||
|
import { Test } from '@nestjs/testing'
|
||||||
|
import type { INestApplication } from '@nestjs/common'
|
||||||
|
import * as request from 'supertest'
|
||||||
|
|
||||||
|
import { AppModule } from '../src/app.module'
|
||||||
|
|
||||||
|
describe('AppController (e2e)', () => {
|
||||||
|
let app: INestApplication
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
|
imports: [AppModule]
|
||||||
|
}).compile()
|
||||||
|
|
||||||
|
app = moduleFixture.createNestApplication()
|
||||||
|
await app.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('/ (GET)', () => {
|
||||||
|
return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!')
|
||||||
|
})
|
||||||
|
})
|
9
test/jest-e2e.json
Normal file
9
test/jest-e2e.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"moduleFileExtensions": ["js", "json", "ts"],
|
||||||
|
"rootDir": ".",
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testRegex": ".e2e-spec.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
}
|
||||||
|
}
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"declaration": true,
|
||||||
|
"removeComments": true,
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"target": "es2017",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "./dist",
|
||||||
|
"incremental": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user