diff --git a/app.js b/app.js index c8cf6f8..31f0401 100644 --- a/app.js +++ b/app.js @@ -3,8 +3,11 @@ dotenv.config(); checkEnv(); import express from "express"; import fetch from "node-fetch"; +import cors from "cors"; + const app = express() +app.use(cors()); const port = process.env["PORT"] || 3000; const allowedRpcs = process.env["ALLOWED_RPCS"].split(","); @@ -38,7 +41,7 @@ async function makeRpc(name, ...params){ return { status: imATeapot, response: obj.error.message }; } else { const ok = 200; - return { status: ok, response: obj.result }; + return { status: ok, response: JSON.stringify(obj.result) }; } }catch(error){ if (error.errno === "ECONNREFUSED") { diff --git a/package-lock.json b/package-lock.json index 9d66bb6..254f561 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "cors": "^2.8.5", "dotenv": "^16.0.3", "express": "^4.18.2", "node-fetch": "^3.2.10" @@ -106,6 +107,18 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "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/data-uri-to-buffer": { "version": "4.0.0", "license": "MIT", @@ -454,6 +467,14 @@ "url": "https://opencollective.com/node-fetch" } }, + "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.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", @@ -749,6 +770,15 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "data-uri-to-buffer": { "version": "4.0.0" }, @@ -984,6 +1014,11 @@ "formdata-polyfill": "^4.0.10" } }, + "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==" + }, "object-inspect": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", diff --git a/package.json b/package.json index 1fb90b8..2f25d07 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ }, "homepage": "https://github.com/Shangaman/PivxNodeController#readme", "dependencies": { + "cors": "^2.8.5", "dotenv": "^16.0.3", "express": "^4.18.2", "node-fetch": "^3.2.10"