Allow webhook connections

This commit is contained in:
MeowcaTheoRange 2024-02-22 08:29:31 -06:00
parent 3e2e31e4a4
commit aed9113b8d
2 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@ require('dotenv').config();
const express = require('express'); const express = require('express');
const { createServer } = require('node:http'); const { createServer } = require('node:http');
const { Server } = require('socket.io'); const { Server } = require('socket.io');
const { fork } = require("child_process");
const app = express(); const app = express();
const server = createServer(app); const server = createServer(app);
@ -15,6 +16,23 @@ io.on('connection', (socket) => {
}) })
}); });
app.get("/webscrobbler", (req, res) => {
res.status(204).end();
})
app.post("/webscrobbler", (req, res) => {
if (req.query.password === process.env.NOTIFICATION_SERVER_PASSWORD) {
const process = fork("./index.js");
process.on('error', function (err) {
res.status(500).end();
});
process.on('exit', function (code) {
res.status(204).end();
});
}
else res.status(403).end();
})
server.listen(process.env.NOTIFICATION_SERVER_PORT, () => { server.listen(process.env.NOTIFICATION_SERVER_PORT, () => {
console.log(`server running on port ${process.env.NOTIFICATION_SERVER_PORT}`); console.log(`server running on port ${process.env.NOTIFICATION_SERVER_PORT}`);
}); });

View file

@ -9,6 +9,7 @@
"author": "abtmtr.link", "author": "abtmtr.link",
"license": "KKPL-2.2", "license": "KKPL-2.2",
"dependencies": { "dependencies": {
"child_process": "^1.0.2",
"commander": "^12.0.0", "commander": "^12.0.0",
"dotenv": "^16.4.4", "dotenv": "^16.4.4",
"express": "^4.18.2", "express": "^4.18.2",