Skip to content

Commit

Permalink
Used proper object
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Nov 22, 2022
1 parent 46dd86e commit a4ecfa3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const port = process.env["PORT"] || 3000;
const rpcPort = process.env["RPC_PORT"] || 51473;
const testnetRpcPort = process.env["TESTNET_RPC_PORT"];
const allowedRpcs = process.env["ALLOWED_RPCS"].split(",");
const server = setupServer();

function setupServer() {
function setupServer(app) {
const certificatePath = process.env["HTTPS_CERTIFICATE_PATH"];
const keyPath = process.env["HTTPS_KEY_PATH"];
if (!certificatePath || !keyPath) {
Expand Down Expand Up @@ -81,7 +80,7 @@ function parseParams(params) {
.map(v=>v === "false" ? false : v);
}

server.get('/mainnet/:rpc', async function(req, res) {
app.get('/mainnet/:rpc', async function(req, res) {
try {
if (allowedRpcs.includes(req.params["rpc"])) {

Expand All @@ -95,11 +94,11 @@ server.get('/mainnet/:rpc', async function(req, res) {
} catch (e) {
console.error(e);
const internalError = 500;
res.status(internalError).send("Internal server error");
res.status(internalError).send("Internal app error");
}
});
if(testnetRpcPort) {
server.get('/testnet/:rpc', async function(req, res) {
app.get('/testnet/:rpc', async function(req, res) {
try {
if (allowedRpcs.includes(req.params["rpc"])) {

Expand All @@ -112,11 +111,13 @@ if(testnetRpcPort) {
}
} catch (e) {
const internalError = 500;
res.status(internalError).send("Internal server error");
res.status(internalError).send("Internal app error");
}
});
}

const server = setupServer(app);

server.listen(port, () => {
console.log(`Pivx node controller listening on port ${port}`)
})

0 comments on commit a4ecfa3

Please sign in to comment.