π’ Docker Prisma Jwt Improv.
$ npm run go
Use Postman or Insomnia
- POST http://localhost:10086/auth/signup
- bring two fields :
mail
andpass
- bring two fields :
- POST http://localhost:10086/auth/signin
- bring two fields :
mail
andpass
- bring two fields :
- POST http://localhost:10086/auth/logout
- Header > Authorization > Bearer +
$access_token
- Header > Authorization > Bearer +
- POST http://localhost:10086/auth/refresh
- Header > Authorization > Bearer +
$refresh_token
- Header > Authorization > Bearer +
$ docker stop $(docker ps -a -q)
or
$ docker compose down
$ docker ps
π’ Docker Prisma JWT
$ npm run go
Use Postman or Insomnia
- POST http://localhost:10086/auth/signup
- bring two fields :
mail
andpass
- bring two fields :
- POST http://localhost:10086/auth/signin
- bring two fields :
mail
andpass
- bring two fields :
- POST http://localhost:10086/auth/logout
- Header > Authorization > Bearer +
$access_token
- Header > Authorization > Bearer +
- POST http://localhost:10086/auth/refresh
- Header > Authorization > Bearer +
$refresh_token
- Header > Authorization > Bearer +
$ docker stop $(docker ps -a -q)
or
$ docker compose down
$ docker ps
π’ ngx β’ NGINX demo
$ cd ~
$ cd /usr/local/etc/nginx
$ nginx
or
$ nginx -c /___path___/nginx.conf
use -s: Signal
$ nginx -s stop
$ nginx -s reload
- Build image
Build docker image
$ docker build . -t imagename
- Build container(s)
Run containers based on the image
$ docker run -p 7777:10086 -d imagename
$ docker run -p 8888:10086 -d imagename
$ docker run -p 9999:10086 -d imagename
- Visite any one of the servers defined above
> http://localhost:PORT
- Nginx
$ nginx
Check the backlog for proofs
- In case of bad luck
$ ps -ef | grep nginx
$ kill -9 PID
$ docker stop $(docker ps -aq)
π’ OAUTH 42
- Go to Settings > API > register a new app
- Set Redirect URI to http://localhost:10086/auth/42/callback
$ npm run go
or
$ npm i
$ npm run start:dev
π’ OAUTH Google
- Go to https://console.cloud.google.com/apis/credentials
- Set Redirect URI to http://localhost:10086/auth/google/callback
$ npm run go
or
$ npm i
$ npm run start:dev
π’ SNL β’ Serve next line
$ make
$ nc -v localhost PORT
$ nc -v "nchamber-nseat" PORT
* on another post
π’ Create a WebSocket gateway
Doc: Gateways | NestJS
*
β
$ npm run start:dev
$ npm i --save @nestjs/websockets @nestjs/platform-socket.io
$ nest new e0-websocket-gateway
β [recv]: listen on 'Major Tom' in [Events]
β
β [send]: send to 'Ground Control' (pattern to be fulfilled)
β [send]: fill in [Message]
β
β Connect β http://localhost:10086
β Postman β New β Socket.IO request
β
*** Test: sending request on Postman ***
- Postman: β
- Insomnia: No Socket IO support
import { Module } from "@nestjs/common";
import { myGateway } from "./gateway";
@Module({
providers: [myGateway]
})
export class GatewayModule {}
// src/gateway/gateway.ts
import { OnModuleInit } from "@nestjs/common";
import { Server } from "socket.io";
import {
MessageBody,
SubscribeMessage,
WebSocketGateway,
WebSocketServer
} from "@nestjs/websockets";
@WebSocketGateway()
export class myGateway implements OnModuleInit {
@WebSocketServer()
server: Server
private connCount: number = 0
// private disconnCount: number = 0
private replyArray: string[] = [
'Hello', 'Good morning', 'Buon giorno', 'Ohayo', 'Buenas dias', 'Where are you going', 'Thank you, God', 'You woke up',
'My life is now about to have some meaning',
'I fix you breakfast'
]
onModuleInit() {
this.server.on( // StrictEventEmitter.on<ev>(ev: 'conn', listener: (sock) => void) /// proto
'connect', // @param ev: "connection|connect"
(sock) => { // @param listener: callback func
console.log('Server', sock.id, 'connected', `(${this.connCount++})`)
sock.on( // StrictEventEmitter.on<ev>(ev: 'conn', listener: (sock, dscp?) => void) /// proto
'disconnect', // @param ev: "disconnect"
(reason, dscp) => { // @param listener: callback func
console.log(
'Server', sock.id, 'disconnected',
`(reason: ${reason}, dscp: ${dscp})`
)
}
)
}
)
// This way to listen to 'disconn' won't work. Correct way above
/*
this.server.on(
'disconnect',
(reason, dscp) => {
console.log(
'Server', 'disconnected',
`(reason: ${reason}, dscp: ${dscp})`
)
}
)
*/
}
onModuleDestroy(signal: string) {
console.log(signal, 'disconnected')
}
@SubscribeMessage('Ground Control') // param: a pattern to be fulfilled
onNewMsg (@MessageBody () payload: any) {
console.log( payload )
this.server.emit(
'Major Tom',
`${this.replyArray[Math.floor(Math.random() * this.replyArray.length)]}! (original text: \"${payload}\")`
)
}
}
π’ Make a client socket
Doc: Gateways | NestJS
*
β
$ npm run start:dev
$ npm install socket.io-client
$ nest new e2-websocket-client
// src/socket/socket.ts
import { Injectable } from "@nestjs/common";
import { Socket, io } from "socket.io-client";
@Injectable()
export class SocketClient {
public sockCli: Socket
constructor () {
this.sockCli = io('http://localhost:10086')
}
onModuleInit () {
this.sockCli.on( // Emitter.on<ev>(ev:'conn', listener:() => void)
'connect',
() => {
console.log('connected to gateway:')
}
)
this.sockCli.on('Major Tom', (payload) => {console.log(payload)})
}
}
// src/socket/socket.module.ts
import { Module } from "@nestjs/common";
import { SocketClient } from "./socket";
@Module({
providers: [SocketClient],
})
export class SocketModule {}
All projects sprawned from
nuoxoxo/nn
Backender 2 is here
gobacker