I am developing a module of MM.
By the way, I want to control one of these modules by an external client, and I want to do that control method by REST API method.
For example, if an external client sends a POST API to MM2, the corresponding message is displayed on the MM2 screen.
I don’t know because I haven’t read the MM2 code in detail, but as far as I’ve checked, the server also automatically turns on when running MM2, so I want to process REST API communication on that server as well, but which file should I modify and put a phrase related to REST API communication in order that?
server.js?
server_function.js?
Examples of API codes that I want to put in are these.
The API code is an API that stores the message as a txt file when a message is transmitted in a POST method.
app.post('/api/saveMessage', (req, res) => {
const message = req.body.message;
if (!message) {
res.status(400).send('Message not provided.');
return;
}
fs.unlink(`appid.txt`, (err) => {
fs.appendFile(`appid.txt`, message + '\n', (err) => {
if (err) {
console.error('Error saving message:', err);
res.status(500).send('Error saving message');
} else {
res.send('The message was saved successfully..');
}
});
});
});