Got the save config route working in the node server

This commit is contained in:
Alicia Sykes
2021-06-19 13:47:10 +01:00
parent 106103a7df
commit 760c464c19
2 changed files with 31 additions and 54 deletions

View File

@@ -63,13 +63,15 @@ try {
printWarning(`Error running ping check for ${req.url}\n`, e);
}
})
.use('/api', method('GET', (req, res) => res.end('hi!')))
// POST Endpoint used to save config, by writing conf.yml to disk
.use('/api/save', method('POST', (req, res) => {
saveConfig(req.body, async (results) => {
await res.end(results);
});
// res.end('Will Save');
try {
saveConfig(req.body, (results) => {
res.end(results);
});
} catch (e) {
res.end(JSON.stringify({ success: false, message: e }));
}
}))
// Finally, initialize the server then print welcome message
.listen(port, () => {