I needed to extend express to send an API request to an internal endpoint whenever the application starts to reattach workers to bull queues. It doesn’t depend on nodemon events etc.
You can use it by creating a file myfile.js in /extensions/server_connect/routes
Use dotenv if you need API tokens or other credentials.
const request = require("request");
let requestSent = false;
exports.handler = function (app) {
if (requestSent) return;
requestSent = true;
const options = {
method: "POST",
url: "myapp.url",
headers: {
Authorization: "Bearer YOUR_TOKEN",
},
};
request(options, (error, response, body) => {
if (error) throw new Error(error);
console.log(body);
});
};
Here are my first example (setting a variable), and the other two use the exports.before and exports.after hooks in case anybody needs them. I added dotenv as well.
I’m using these to call an internal endpoint that runs a custom module that gets all Bull Queues from my Redis cluster that still have pending or waiting jobs. I coded that last night, and it works well. It might be something you can make use of as well.
I’ve already put it into use, as I just happened to need it this morning. I have it deleting any previously stored websocket id’s that do not get removed on a server restart. It was the perfect fix!