🔑 Added credentials for rabbitMQ connection

This commit is contained in:
2021-10-14 18:22:36 -07:00
parent e878daa114
commit 86b9ec9d95

View File

@@ -19,6 +19,9 @@ app.use(bodyParser.urlencoded({ extended: true }));
const port: number = Number(process.env.PORT) || 8050; // set our port const port: number = Number(process.env.PORT) || 8050; // set our port
// set rabbitMQ host // set rabbitMQ host
const rabbitMQHost = process.env.RABBITMQHOST || "localhost"; const rabbitMQHost = process.env.RABBITMQHOST || "localhost";
const rabbitMQCredentials =
`${process.env.RABBITMQ_USERNAME}:${process.env.RABBITMQ_PASSWORD}` ||
`guest:guest`;
// Send index.html on root request // Send index.html on root request
app.use(express.static("dist")); app.use(express.static("dist"));
@@ -45,7 +48,9 @@ io.on("connection", (socket) => {
}); });
}); });
amqp.connect(`amqp://${rabbitMQHost}`, (error0, connection) => { amqp.connect(
`amqp://${rabbitMQCredentials}@${rabbitMQHost}`,
(error0, connection) => {
if (error0) { if (error0) {
throw error0; throw error0;
} }
@@ -65,14 +70,18 @@ amqp.connect(`amqp://${rabbitMQHost}`, (error0, connection) => {
queue, queue,
(data) => { (data) => {
//Socket Trigger All Clients //Socket Trigger All Clients
io.sockets.emit("coverExtracted", JSON.parse(data.content.toString())); io.sockets.emit(
"coverExtracted",
JSON.parse(data.content.toString()),
);
}, },
{ {
noAck: true, noAck: true,
}, },
); );
}); });
}); },
);
// socket server // socket server
httpServer.listen(8051); httpServer.listen(8051);