graph TD;
Clinet-->ServerA;
ServerA-->Clinet;
MongoAtlas-->ServerB;
Imagga-->ServerB;
ServerB-->Imagga;
ServerB-->MailGun;
ServerA-->S3;
ServerA-->RabbitMQ;
ServerA-->MongoAtlas;
RabbitMQ-->ServerB;
S3-->ServerB;
sequenceDiagram
loop ServerA: Listenint to Client
Client->>+ServerA: Request
ServerA->>+MongoAtlas: Add Data to Database
MongoAtlas-->>-ServerA: ACK
ServerA->>+ArvanCloudS3: Upload Image to S3
ArvanCloudS3-->>-ServerA: ACK
ServerA->>+AmqpCloud: Send ID
AmqpCloud-->>-ServerA: ACK
ServerA-->>-Client: Response
end
loop ServerB: Listening to Queue
AmqpCloud-->>+ServerB: ID
ServerB-->>+Imagga: Image URL
Imagga-->>-ServerB: Process Result
ServerB->>+MongoAtlas: Update Ad Status
MongoAtlas-->>-ServerB: ACK
ServerB->>+Mailgun: Send Email
Mailgun-->>-ServerB: ACK
end
Run the following command to install needed packages:
npm i
Create a src/credentials.js
with this content:
const credentials = {
mongodb: {
url: '...',
},
mailgun: {
domain: '...',
apiKey: '...',
},
imagga: {
authorization: '...',
},
amqp: {
url: '...',
queueKey: '...',
},
s3: {
secretKey: '...',
accessKey: '...',
endpointUrl: '...',
region: '...',
bucketName: '...',
bucketContentUrlPrefix: '...',
},
}
module.exports = credentials;
Following command will start server A on port 3001
and server B on port 3002
and
clients will be able to sent their request to server A.
node src # running src/index.js
localhost:3001/
response Example:
{
"result": "OK",
"message": "Server A is UP!"
}
localhost:3001/ad
response Example:
{
"result": "OK",
"data": [
{
"id": 1,
"description": "a simple description",
"email": "[email protected]",
"state": "PENDING",
"category": "UNKNOWN",
"image": "..."
},
{
"id": 2,
"description": "a great red sport car!",
"email": "[email protected]",
"state": "APPROVED",
"category": "sports car",
"image": "..."
},
]
}
localhost:3001/ad/:id
response Example:
{
"result": "OK",
"data": {
"id": 2,
"description": "a great red sport car!",
"email": "[email protected]",
"state": "APPROVED",
"category": "sports car",
"image": "..."
}
}
localhost:3001/ad
Body (Form Data):
Field Name | Type |
---|---|
image | File (.jpg) |
String | |
description | String |
response Example:
{
"result": "OK",
"message": "آگهی شما با شناسهی 3 ثبت گردید.",
"data": {
"id": 3,
"description": "a simple description",
"email": "[email protected]",
"state": "PENDING",
"image": "...",
"category": "UNKNOWN"
}
}
localhost:3001/ad/:id
response Example:
{
"result": "OK",
"data": {
"acknowledged": true,
"deletedCount": 1
}
}
localhost:3001/ad
response Example:
{
"result": "OK",
"data": {
"acknowledged": true,
"deletedCount": 20
}
}