From 50efc0baa931225010246e0b653d424060e0642c Mon Sep 17 00:00:00 2001 From: Yurii Kovalchuk <103324562+yumirkov@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:41:14 +0300 Subject: [PATCH] ATOR-320 - Add observed_bandwidth and measured fields to relay search (#12) --- operations/deploy-stage.hcl | 4 ++-- package-lock.json | 31 +++++++++++++++++++++++++++++++ package.json | 2 ++ src/app.ts | 6 +++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/operations/deploy-stage.hcl b/operations/deploy-stage.hcl index 9886648..423e7e5 100755 --- a/operations/deploy-stage.hcl +++ b/operations/deploy-stage.hcl @@ -15,10 +15,10 @@ job "api-service-stage" { } } - volume "api-service-live" { + volume "api-service-stage" { type = "host" read_only = false - source = "api-service-live" + source = "api-service-stage" } task "api-service-stage-task" { diff --git a/package-lock.json b/package-lock.json index c5798ed..7bc480e 100755 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@types/express": "^4.17.21", "@types/geoip-lite": "^1.4.4", "axios": "^1.6.8", + "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.1", "express-validator": "^7.1.0", @@ -19,6 +20,7 @@ "h3-js": "^4.1.0" }, "devDependencies": { + "@types/cors": "^2.8.17", "@types/jest": "^29.5.12", "@types/node": "^20.11.30", "@types/supertest": "^6.0.2", @@ -1175,6 +1177,15 @@ "integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==", "dev": true }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/express": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", @@ -1920,6 +1931,18 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", "dev": true }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -3847,6 +3870,14 @@ "node": ">=8" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", diff --git a/package.json b/package.json index c7ecfb6..e3f1992 100755 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "ISC", "devDependencies": { + "@types/cors": "^2.8.17", "@types/jest": "^29.5.12", "@types/node": "^20.11.30", "@types/supertest": "^6.0.2", @@ -24,6 +25,7 @@ "@types/express": "^4.17.21", "@types/geoip-lite": "^1.4.4", "axios": "^1.6.8", + "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.1", "express-validator": "^7.1.0", diff --git a/src/app.ts b/src/app.ts index 29ff6ed..23ef293 100755 --- a/src/app.ts +++ b/src/app.ts @@ -1,5 +1,6 @@ import express from 'express'; import bodyParser from 'body-parser'; +import cors from 'cors'; import { body, validationResult } from 'express-validator'; import { VictoriaMetricsService } from './VictoriaMetricsService'; import { OnionooService, HardwareInfo } from './OnionooService'; @@ -11,6 +12,7 @@ dotenv.config(); const app = express(); app.use(bodyParser.json()); +app.use(cors()); const PORT = process.env.PORT ?? 3000; const vmService = new VictoriaMetricsService(process.env.VICTORIA_METRICS_ADDRESS as string); @@ -72,7 +74,9 @@ app.get('/relays/:fingerprint', async (req, res) => { const relay = { fingerprint: foundRelay.fingerprint, running: foundRelay.running, - consensus_weight: foundRelay.consensus_weight + consensus_weight: foundRelay.consensus_weight, + observed_bandwidth: foundRelay.observed_bandwidth, + measured: foundRelay.measured }; console.log('Relay:', relay); return res.json(relay);