38 lines
No EOL
1 KiB
JavaScript
38 lines
No EOL
1 KiB
JavaScript
require('dotenv').config();
|
|
const express = require('express');
|
|
const { createServer } = require('node:http');
|
|
const { Server } = require('socket.io');
|
|
const { fork } = require("child_process");
|
|
|
|
const app = express();
|
|
const server = createServer(app);
|
|
const io = new Server(server);
|
|
|
|
io.on('connection', (socket) => {
|
|
console.log('A client connected!');
|
|
socket.on('nodeMessage', (msg) => {
|
|
if (msg.password === process.env.NOTIFICATION_SERVER_PASSWORD)
|
|
io.emit('message', msg.message);
|
|
})
|
|
});
|
|
|
|
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, () => {
|
|
console.log(`server running on port ${process.env.NOTIFICATION_SERVER_PORT}`);
|
|
}); |