41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import express from 'express';
|
|
import { readFileSync, existsSync } from "fs";
|
|
|
|
import {Config, getRegistry} from './config.js'
|
|
|
|
import {RegHelper} from './deployments.js'
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.use(function(_req, res, next) {
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
|
next();
|
|
});
|
|
|
|
app.get('/', async (_req, res) => {
|
|
const reg = new RegHelper();
|
|
const regStatus= await reg.deploymentRequestStatus();
|
|
if (Config.DEPLOYER_STATE && existsSync(Config.DEPLOYER_STATE)) {
|
|
const deployerState = JSON.parse(readFileSync(Config.DEPLOYER_STATE).toString());
|
|
for (const r of regStatus) {
|
|
if (deployerState[r.id] && deployerState[r.id].status && deployerState[r.id].status != "SEEN") {
|
|
console.log(deployerState[r.id])
|
|
r.lastState = deployerState[r.id].status;
|
|
}
|
|
}
|
|
}
|
|
res.send(regStatus);
|
|
});
|
|
|
|
app.get('/:id', async (req, res) => {
|
|
const registry = getRegistry();
|
|
const records = await registry.getRecordsByIds([req.params.id]);
|
|
res.send(records);
|
|
});
|
|
|
|
app.listen(Config.LISTEN_PORT, Config.LISTEN_ADDR, () => {
|
|
console.log(`listening on ${Config.LISTEN_ADDR}:${Config.LISTEN_PORT}`);
|
|
});
|