- For Production solution, i used Redis, please see the list event-publishing system
- In this solution, we are using Redis PubSub for AWS Production server
- On Local server, we are still using the normal Apollo PubSub comes with NESTJS. See
pubsub.module.ts
- By default, Javascript objects are serialized using the JSON.stringify and JSON.parse methods. This means that not all objects - such as Date or Regexp objects - will deserialize correctly without a custom reviver, that work out of the box with the default in-memory implementation. In our case, ObjectId, Date in
MessageDocument
will need a custom reviver. - Notes: The data we receive from Redis PubSub will need to be deserialized to JSON format in
message.service.ts
, before the resolvers can handle it. For this we are using custom-reviver
NodeJS v20X
npm i @nestjs/config @nestjs/mongoose mongoose
npm i joi
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-os-x/
brew tap mongodb/brew
brew update
brew install mongodb-community@7.0
-
kill MongoDB process: https://stackoverflow.com/questions/11774887/how-to-stop-mongo-db-in-one-command
mkdir -p ~/data/db
chmod 777 ~/data/db
mongod --dbpath ~/data/db
-
Normally MongoDb will be started on 127.0.0.1:27017
-
Connection string should be
mongodb://127.0.0.1:27017/chatter
-
How to use MongoDB Model
-
How to use MongoDb method
-
- Installing:
npm i @nestjs/graphql @nestjs/apollo @apollo/server graphql
- Playground GraphQL server, after starting backend:
http://localhost:3001/graphql
- Understand NestJS GraphQL: https://docs.nestjs.com/graphql/quick-start
https://www.mongodb.com/try/download/compass https://www.mongodb.com/docs/compass/current/query/filter/?utm_source=compass&utm_medium=product
npm i migrate-mongo
npm i --save-dev @types/migrate-mongo
nest g module auth
nest g service auth
npm i --save class-validator class-transformer
ValidationPipe
openssl version
openssl genrsa 2048 > privatekey.pem
stat privatekey.pem
openssl req -new -key privatekey.pem -out csr.pem
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:Washington
Locality Name (eg, city) []:Seattle
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Example Corporation
Organizational Unit Name (eg, section) []:Marketing
Common Name (e.g. server FQDN or YOUR name) []:prod.eba-cnqkbmvr.us-west-2.elasticbeanstalk.com
Email Address []:thangtran3112@gmail.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:sometestpassword
An optional company name []:
openssl x509 -req -days 365 -in csr.pem -signkey privatekey.pem -out public.crt
- Upload public.crt to AWS Beanstalk with AWS CLI
brew install awscli
aws --version
aws configure
AWS Access Key ID [None]: ************************
AWS Secret Access Key [None]: *************************************
Default region name [None]: us-west-2
Default output format [None]:
aws iam upload-server-certificate --server-certificate-name elastic-beanstalk-x509 --certificate-body file://public.crt --private-key file://privatekey.pem
- Enable CORS in
main.ts
throughapp.enableCors();
- Enable CORS for GraphQLModule inside
app.module.ts
throughcors: true
- By default, AWS does not allow setting cookie with different CORS origin