From 3e06856c700abe0a2a6f0a76aef15e1b1243c1a5 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 30 Oct 2024 14:20:55 +0000 Subject: [PATCH 1/2] Added cors --- package.json | 1 + src/daemon.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f42641e..f66f62b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "", "license": "MIT", "dependencies": { + "cors": "^2.8.5", "express": "^4.21.1", "i2c-bus": "^5.2.3", "serialport": "^12.0.0" diff --git a/src/daemon.js b/src/daemon.js index ea9c600..d85ffc4 100644 --- a/src/daemon.js +++ b/src/daemon.js @@ -1,3 +1,4 @@ +import cors from 'cors'; import express from 'express'; import path from 'path'; import APOLLO from './apollo.js'; @@ -13,7 +14,9 @@ export default class Daemon { this.express = express(); - this.express.get('/api/*', async (req, res) => { + this.express.use(cors('*')); + + this.express.get('/api/*', async (req, res) => { const cmd = req.params['0']; res.json(await this.run(cmd)); }); From f5e1d739885c009f00131077cd1543ded677da27 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 30 Oct 2024 14:27:55 +0000 Subject: [PATCH 2/2] Fixed moved utilies --- package-lock.json | 7 +++++++ package.json | 2 +- src/sensor-suite.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fea41ff..c77fd30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "license": "MIT", "dependencies": { + "@ztimson/utils": "^0.21.6", "cors": "^2.8.5", "express": "^4.21.1", "i2c-bus": "^5.2.3", @@ -220,6 +221,12 @@ "url": "https://opencollective.com/serialport/donate" } }, + "node_modules/@ztimson/utils": { + "version": "0.21.6", + "resolved": "https://registry.npmjs.org/@ztimson/utils/-/utils-0.21.6.tgz", + "integrity": "sha512-wOjwd9N6m73NgsuCIWr1yrmWwp7CLoDu6vdlhE0CiXhEqzC9qRhkOcP8Sgn7n0nK3RANlwDtYKJl02iuRAcoJw==", + "license": "MIT" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", diff --git a/package.json b/package.json index 861d4da..f4d2567 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "type": "module", "scripts": { - "start": "node src/main.js" + "apollo": "node src/main.js" }, "author": "", "license": "MIT", diff --git a/src/sensor-suite.js b/src/sensor-suite.js index df0fd64..c13ee5a 100644 --- a/src/sensor-suite.js +++ b/src/sensor-suite.js @@ -1,4 +1,4 @@ -import {adjustedInterval, sleep} from './misc.js'; +import {adjustedInterval, sleep} from '@ztimson/utils'; import {bms} from './bms.js'; import {bme} from './bme280.js';