Workstations Service
This commit is contained in:
parent
9a2bd2bffd
commit
072a75ef28
73 changed files with 841 additions and 1 deletions
39
backend/workstations/workstations.js
Normal file
39
backend/workstations/workstations.js
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue