Workstations Service

This commit is contained in:
Henrik Brüsecke 2026-08-29 18:18:56 +03:00
parent 9a2bd2bffd
commit 2efe5cd224
77 changed files with 978 additions and 2 deletions

View file

@ -0,0 +1,39 @@
import fs from 'node:fs';
import http from 'node:http';
import * as yaml from 'js-yaml';
const LOCALE = 'en';
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(compareWorkstations);
const workstationsJSON = JSON.stringify(workstations);
const server = http.createServer(onRequest);
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
server.listen(50000);
function compareWorkstations(first, second) {
const osComparison = first.os.localeCompare(second.os, LOCALE);
const versionComparison = second.version.localeCompare(first.version, LOCALE, { numeric: true });
return osComparison || versionComparison;
}
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();
}