import fs from 'node:fs'; import http from 'node:http'; import * as yaml from 'js-yaml'; const yamlFiles = fs.globSync(`${import.meta.dirname}/data/**/*.yaml`); const yamlContents = yamlFiles.map(yamlFile => fs.readFileSync(yamlFile, 'utf8')); const workstations = yamlContents.map(yamlContent => yaml.load(yamlContent)); workstations.sort((first, second) => first.os.localeCompare(second.os) || first.version.localeCompare(second.version, 'en', { numeric: true }) ) const workstationsJSON = JSON.stringify(workstations); const server = http.createServer(onRequest); process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown); server.listen(50000); function onRequest(_request, response) { response.setHeader('Content-Type', 'application/json'); response.end(workstationsJSON); } function shutdown() { process.off('SIGINT', shutdown); process.off('SIGTERM', shutdown); server.close(); }