/*
    ! /servers/Dashboard/functions.js – Central Dashboard Server Functions
    ? This modules exports the functionality for the express dashboard server
*/

// % core variables
const ip = process.env.INTERNAL_HOST_IP;
const port = process.env.INTERNAL_DASHBOARD_PORT;

// $ server start function
async function boot(server) {
    // ~ start express server
    server.listen(port, ip, () => {
        console.info(`Express server is now running on http://${ip}:${port}`)
    });

    // ~ return running express server reference
    return server;
};

// $ server shutdown function
async function shutdown(server) {
    // ~ shutdown running express server
    server.close();

    // ~ return express server reference
    return server;
};

// $ server restart function
async function restart(server) {
    // ~ shutdown the running express server
    await shutdown(server);

    // ~ restart the express server
    await boot(server);

    // ~ return the server reference
    return server;
};

// $ server status function
async function status(server) {
    // ~ get and return server listening status
    return server.listening ? 'online' : 'offline';
};

// § export server functions module
module.exports = { boot, shutdown, restart, status };