Add restart endpoint for git to auto restart server from main
This commit is contained in:
parent
dab4e6b8f2
commit
b82895332a
13
index.js
13
index.js
|
@ -731,6 +731,19 @@ app.get('/api/v1', (req, res) => { // Backwards compatibility with TandmX cause
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Management Routes (Like restarting the server)
|
||||||
|
app.post("/api/v1/manage/restart", (req, res) => {
|
||||||
|
// Check Authorization header against process.env.MANAGEMENT_AUTH
|
||||||
|
if (req.headers.authorization !== (process.env.MANAGEMENT_AUTH || crypto.randomBytes(32).toString('hex'))) { // Default to random in case we forget to configure it
|
||||||
|
res.status(401).send("Unauthorized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.status(200).send("Restarting server...");
|
||||||
|
setTimeout(() => {
|
||||||
|
process.exit(0);
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Listening on port ${port}`);
|
console.log(`Listening on port ${port}`);
|
||||||
|
|
Loading…
Reference in a new issue