Workstations Service

This commit is contained in:
Henrik Brüsecke 2026-08-29 18:18:56 +03:00
parent 9a2bd2bffd
commit e78e390368
6 changed files with 95 additions and 1 deletions

View file

@ -0,0 +1,33 @@
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();
}